Ciao a tutti, ho uno script che controlla l'accesso al sito, usando questa query :
estraggo dal db un utente,codice:query = "SELECT id_utente, username, password FROM utenti WHERE username='$username' AND password='$password'";
quando eseguo la query, come faccio a controllare se l'utente c'e' oppure no?
ho provato cosi:
e sempbra funzionare, c'è qualche errore che non trovo???codice:if(($result = safe_query($query))){ //nessun risultato, utente non trovato o non presente del db $errore = 2; header("location: index.php?errore=" .$errore); //oppure header("location: index.php?errore='$errore'); //oppure header("location: index.php?errore=$errore); } if(($result = safe_query($query))==TRUE){ //utente trovato, lo identifico $_SESSION['utente']= "user"; $row = mysql_fetch_array($result); $id_user =$row['id_utente']; $_SESSION['utente_id'] = $id_user; //ora registro la sua visita $query = "INSERT INTO accessi_utenti (id_accesso_utenti , id_utente , data , ora ) VALUES ('', '$id_user', '$data', '$time')"; if(mysql_affected_rows() == 1){//inserimento riuscito header("location: elenco.php"); } }




Rispondi quotando
