Comment éviter des doublons pour un formulaire d'inscription?
teddM
Messages postés
8
Date d'inscription
Statut
Membre
Dernière intervention
-
teddM Messages postés 8 Date d'inscription Statut Membre Dernière intervention -
teddM Messages postés 8 Date d'inscription Statut Membre Dernière intervention -
Bonjour à tous,
<?php
$erreur=NULL;
$info=NULL;
if(isset($_POST["submit"]))
{
$nom=htmlspecialchars(trim($_POST['nom']));
$email=htmlspecialchars(trim($_POST['email']));
if($nom&&$email )
{
if( preg_match("#^[a-z0-9.8_-]+@[a-z0-9.8_-]{2,}\.[a-z]{2,}$#",$email))
{
$connect=mysql_connect('localhost','root','');
mysql_select_db('phpenregistr');
$enreg=mysql_query("INSERT INTO prospect VALUES('','$nom','$email') ");
$info="Vous êtes désormais dans la listes des gagneurs surveillez vos mails";
}else{$erreur="Verifiez que le format de l'email est correct exemple: moi@nomserveur.com";}
}else {$erreur="Verifiez que tous les champs sont remplit s'il vous plaît!";};
}
?>
<?php
$erreur=NULL;
$info=NULL;
if(isset($_POST["submit"]))
{
$nom=htmlspecialchars(trim($_POST['nom']));
$email=htmlspecialchars(trim($_POST['email']));
if($nom&&$email )
{
if( preg_match("#^[a-z0-9.8_-]+@[a-z0-9.8_-]{2,}\.[a-z]{2,}$#",$email))
{
$connect=mysql_connect('localhost','root','');
mysql_select_db('phpenregistr');
$enreg=mysql_query("INSERT INTO prospect VALUES('','$nom','$email') ");
$info="Vous êtes désormais dans la listes des gagneurs surveillez vos mails";
}else{$erreur="Verifiez que le format de l'email est correct exemple: moi@nomserveur.com";}
}else {$erreur="Verifiez que tous les champs sont remplit s'il vous plaît!";};
}
?>
A voir également:
- Comment éviter des doublons pour un formulaire d'inscription?
- Whatsapp formulaire opposition - Guide
- Wetransfer gratuit sans inscription - Guide
- Éviter pub youtube - Accueil - Streaming
- Formulaire de réclamation facebook - Guide
- Twitter inscription - Guide
2 réponses
Voila un bout de code que j'ai adapter au votre en gros au votre il se peu que sa fonctionne pas car je l'ai pas tester la ligne qui vous intéresse est en gras
$bdd = new PDO('mysql:host=localhost dbname=test', 'root', ''); } catch(Exception $e) { die('Ca deconne grave : ' . $e -> getMessage()); } $repons = $bdd -> prepare('SELECT email FROM membre WHERE email=:email'); $repons -> execute(array('email' => htmlspecialchars($_POST['email']))); $resultat = $repons -> fetch(); if ($repons -> rowCount() != 0) { echo "vous êtes déjà inscrit"; } else { $reponse = $bdd -> prepare('INSERT INTO membre (pseudo, email, ) VALUES(:pseudo, :email)'); $reponse -> execute(array('pseudo' => htmlspecialchars($_POST['pseudo']), 'email' => htmlspecialchars($_POST['email']))); echo ""Vous êtes désormais dans la listes des gagneurs surveillez vos mails"; } }
Utilisateur anonyme
non c est pas juste il faut enregistrer dans la bas de donnée apres le else...désolé je vous aide pas beaucoup
EN ce qui concerne PHP PDO j'ai pas mal de retard :
donc voila le nouveau code:
<?php
$erreur=NULL;
$info=NULL;
if(isset($_POST["submit"]))
{
$nom=htmlspecialchars(trim($_POST['nom']));
$email=htmlspecialchars(trim($_POST['email']));
if($nom&&$email )
{
if( preg_match("#^[a-z0-9.8_-]+@[a-z0-9.8_-]{2,}\.[a-z]{2,}$#",$email))
{
$connect=mysql_connect('localhost','root','');
mysql_select_db('phpenregistr');
$enreg=mysql_query("INSERT INTO prospect VALUES('','$nom','$email') ");
if($enreg -> rowCount() != 0) {
echo "<p>Vou etes déjà inscrit</p>";}
else{
$enreg=mysql_query("INSERT INTO prospect VALUES('','$nom','$email') ");
$info="Vous êtes désormais dans la listes des gagneurs surveillez vos mails";
}
}else{$erreur="Verifiez que le format de l'email est correct exemple: moi@nomserveur.com";}
}else {$erreur="Verifiez que tous les champs sont remplit s'il vous plaît!";};
}
?><?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Formulaire d'inscription des gagneurs</title>
<link rel="stylesheet" type="text/css" href="mise-en-form.css" media="all"/>
</head>
<body >
<form method="post" action="enregistrement.php" enctype="multipart/form-data" />
<h1>Benvenue gagneur!</h1>
<table >
<tr><td><h1>Cher gagneur inscrivez-vous ici!</h1></td></tr>
<tr><td><label for="nom"><b>Nom* :</b></label></td></tr>
<tr><td><input type="text" name="nom" id="nom" placeholder=" Vôtre nom"/></td></tr>
<tr><td><label for="email"><b>Email principale*:</b></label></td></tr>
<tr><td><input type="text" name="email" id="email" placeholder="Vôtre email principal" /></td></tr>
<tr><td><input type="submit" name="submit" value="CLIQUEZ ICI !" id="submit"/> </td></tr>
<tr><td> <span style="color:red;"><?php echo $erreur;?></span>
<span style="color:green;"><?php echo $info;?></span> </td></tr>
</table>
<p>LE VRAI PERDANT C'EST CELUI QUI NE SAISIT PAS LES OCCASIONS QUI SE PRESENTENT Á LUI!<br/>
LE PERDANT NE SAIT PAS GAGNER LES CONCOURS DE CIRCONSTANCE SOYEZ UN GAGNEUR SAISISSEZ L'OCCASION PRESENT!</p>
</body>
</html>
donc voila le nouveau code:
<?php
$erreur=NULL;
$info=NULL;
if(isset($_POST["submit"]))
{
$nom=htmlspecialchars(trim($_POST['nom']));
$email=htmlspecialchars(trim($_POST['email']));
if($nom&&$email )
{
if( preg_match("#^[a-z0-9.8_-]+@[a-z0-9.8_-]{2,}\.[a-z]{2,}$#",$email))
{
$connect=mysql_connect('localhost','root','');
mysql_select_db('phpenregistr');
$enreg=mysql_query("INSERT INTO prospect VALUES('','$nom','$email') ");
if($enreg -> rowCount() != 0) {
echo "<p>Vou etes déjà inscrit</p>";}
else{
$enreg=mysql_query("INSERT INTO prospect VALUES('','$nom','$email') ");
$info="Vous êtes désormais dans la listes des gagneurs surveillez vos mails";
}
}else{$erreur="Verifiez que le format de l'email est correct exemple: moi@nomserveur.com";}
}else {$erreur="Verifiez que tous les champs sont remplit s'il vous plaît!";};
}
?><?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Formulaire d'inscription des gagneurs</title>
<link rel="stylesheet" type="text/css" href="mise-en-form.css" media="all"/>
</head>
<body >
<form method="post" action="enregistrement.php" enctype="multipart/form-data" />
<h1>Benvenue gagneur!</h1>
<table >
<tr><td><h1>Cher gagneur inscrivez-vous ici!</h1></td></tr>
<tr><td><label for="nom"><b>Nom* :</b></label></td></tr>
<tr><td><input type="text" name="nom" id="nom" placeholder=" Vôtre nom"/></td></tr>
<tr><td><label for="email"><b>Email principale*:</b></label></td></tr>
<tr><td><input type="text" name="email" id="email" placeholder="Vôtre email principal" /></td></tr>
<tr><td><input type="submit" name="submit" value="CLIQUEZ ICI !" id="submit"/> </td></tr>
<tr><td> <span style="color:red;"><?php echo $erreur;?></span>
<span style="color:green;"><?php echo $info;?></span> </td></tr>
</table>
<p>LE VRAI PERDANT C'EST CELUI QUI NE SAISIT PAS LES OCCASIONS QUI SE PRESENTENT Á LUI!<br/>
LE PERDANT NE SAIT PAS GAGNER LES CONCOURS DE CIRCONSTANCE SOYEZ UN GAGNEUR SAISISSEZ L'OCCASION PRESENT!</p>
</body>
</html>