allora approfitto del mio thread per porvi un altro problema devo verificare che non venga registrato un nuovo utente con lo stesso username di uno già presente. presi i dati dal form questo è il controllo e inserimento. il problema è che se inserisco lo stesso user la registrazione avviene ugualmente e nel database ho due user o più con lo stesso nome.
Codice PHP:
<?php
$nome = $_POST['nome'];
$cognome = $_POST['cognome'];
$email = $_POST['email'];
$user = $_POST['user'];
$psw = $_POST['psw'];
$rpsw = $_POST['rpsw'];
if($psw!=$rpsw)
{
header('Location: registrazione.html');
}
else
{
include 'db.inc.php';
try
{
$sql = "SELECT * FROM accesso";
$ris = $pdo->query($sql);
$row = $ris->fetch();
if($user == $row['user'])
{
$user_r = "L'username inserito è già utilizzato.";
}
else
{
$user_r = "";
try
{
$sql = 'INSERT INTO accesso SET nome = :nome, cognome = :cognome ,
user = :user , email = :email , psw = :psw, admin = 0 ';
$st = $pdo->prepare($sql);
$st->bindValue(':nome' , $nome);
$st->bindValue(':cognome' , $cognome);
$st->bindValue(':email' , $email);
$st->bindValue(':user' , $user);
$st->bindValue(':psw' , $psw);
$st->execute();
} catch (PDOException $e)
{
$err = 'Errore inserimento dati';
include 'errore.php';
exit();
}
}
} catch(PDOException $e)
{
$err = 'Errore inserimento dati';
include 'errore.php';
exit();
}
include 'risReg.php';
}
?>
e questo è l'include
Codice PHP:
<html>
<head>
<meta charset="utf8">
<title> Esito registrazione </title>
</head>
<body>
<p> La registrazione è: </p>
<?php
if($user_r=="")
{
echo 'riuscita.';
header("refresh:3;url=index.html");
}
else
{
echo 'fallita. Hai inserito un username già utilizzato.';
header("refresh:3;url=registrazione.html");
}
?>
</body>
</html>