2
I would like examples of how to prevent email from being duplicated if a user tries to register multiple.
<form action="processar.php" method="POST">
<input type="text" name="nome">
<input type="email" name="email">
<input type="submit">
</form>
Process.php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "experiments";
//Pega os dados da form
$nome = $_POST['nome'];
$email = $_POST['email'];
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
$dupesql = "SELECT * FROM formulario where (email = '$email')";
$duperaw = mysql_query($dupesql);
if (mysql_num_rows($duberaw) > 0) {
echo "Não deu certo, este e-mail já está cadastrado.";
} else {
$sql = "INSERT INTO formulario (nome, email)
VALUES ('$nome', '$email')";
}
I would do via ajax/jquery, as soon as the user finished typing something, make a query on the server by email, if already existing, warn the user. Something cool and release Submit after all the data is validated, html5o inputs, ajax/jquery, back validation. With ajax you avoid more work.
– Elton da Costa
I recommend using mysqli or PDO since the mysql_* functions are obsolete.
– Marcos Xavier