gpt4 book ai didi

php - 用户存在检查器不起作用

转载 作者:行者123 更新时间:2023-11-30 00:03:24 25 4
gpt4 key购买 nike

我正在为一个网站做一个注册页面,我想检查用户是否存在然后提醒用户。我尝试了不同的方法,但仍然不起作用。这是我的最新代码:

<?php //script pour vérifier et enregistrer les données


if (isset($_POST['submit']))
{
//on récupère les données entrées
$name = ucfirst($_POST['userName']); //mettre le premier caractère en majuscule
$firstName = ucfirst($_POST['firstName']);
$birthDate = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
$languageM = $_POST['langueM']; //langue maternelle
$languageE = $_POST['langueE']; //langue étudiée
$email = $_POST['mailInput'].'@'.$_POST['schools'];
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];


if(isset($name,$firstName,$birthDate,$languageM,$languageE,$email,$password1,$password2))
{

if ($password1===$password2)
{
//hashage du mot de passe
$password1_sha1 = sha1($password1);
$password2_sha1 = sha1($password2);
// taille du nom ou du prénom
if (strlen($name)>25||strlen($firstName)>25)
{
print"<span style=\"color:red;\">Nom ou pr&eacute;nom trop long !</span>";
exit();//plus la peine de continuer
}

else
{
//check password length
if (strlen ($password1)>25 || strlen ($password1)<6)
{
print "<span style=\"color:red;\">Le mot de passe doit etre entre 6 et 25 caract&egrave;res</span>";
exit();
}
else
{

//connection à la bdd
try
{
$bdd = new PDO('mysql:host=localhost;dbname=bladuo', 'root', '');
$bdd->exec('SET NAMES utf8');//affichage caractères utf-8 dans la bdd

$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

//enregistrement de l'étudiant dans la bdd
$stmt = $bdd->prepare('INSERT INTO membres(nom,prenom,date_de_naissance,langue_maternelle,langue_etudiee,email,passe)
VALUES(?, ?, ?, ?, ?, ?, ?)');
$success = $stmt->execute(array($name , $firstName , $birthDate, $languageM , $languageE , $email,$password1_sha1));

if($success)
{
header('Location: Index.php');
}else

{
$stmt= $bdd->prepare("SELECT COUNT(*) AS count FROM `membres` WHERE nom=?");
$stmt->execute(array($name));
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$username_count = $row["count"];
}
//if username is taken
if ($username_count > 0)
{
print "<span style=\"color:red;\">Cet utilisateur existe déjà!</span>";
}
$stmt = $conn->prepare("SELECT COUNT(*) AS count FROM `user` WHERE email=?");
$stmt->execute(array($email));
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$email_count = $row["count"];
}
if ($email_count > 0)
{
print "<span style=\"color:red;\"That email address is already in use<span>";
}
}
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
}

}

}else
{
print "<span style=\"color:red;\">Les mots de passe ne sont pas identiques</span>";
exit();
}

}else
{
print "<span style=\"color:red;\">une des variables nest pas set</span>";
}

}

?>

当我尝试注册现有用户时,它会保存在数据库中。我做错了什么?

最佳答案

我为那些可能遇到同样问题的人更新帖子

<?php //script pour vérifier et enregistrer les données


if (isset($_POST['submit']))
{
//on récupère les données entrées
$name = ucfirst($_POST['userName']); //mettre le premier caractère en majuscule
$firstName = ucfirst($_POST['firstName']);
$birthDate = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
$languageM = $_POST['langueM']; //langue maternelle
$languageE = $_POST['langueE']; //langue étudiée
$email = $_POST['mailInput'].'@'.$_POST['schools'];
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];


if(isset($name,$firstName,$birthDate,$languageM,$languageE,$email,$password1,$password2))
{

if ($password1===$password2)
{
//hashage du mot de passe
$password1_sha1 = sha1($password1);
$password2_sha1 = sha1($password2);
// if user exists
$bdd = new PDO('mysql:host=localhost;dbname=bladuo', 'root', '');
$bdd->exec('SET NAMES utf8');//affichage caractères utf-8 dans la bdd
$stmt= $bdd->prepare("SELECT COUNT(*) AS count FROM `membres` WHERE email=?");
$stmt->execute(array($email));
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$email_count = $row["count"];
}
if ($email_count > 0)
{
print "<span style=\"color:red;\">Addresse email déjà utilisée, veuillez en choisir une autre!</span>";
}

else
{
//check password length
if (strlen ($password1)>25 || strlen ($password1)<6)
{
print "<span style=\"color:red;\">Le mot de passe doit etre entre 6 et 25 caract&egrave;res</span>";
exit();
}

else
{
//connection à la bdd
try
{
$bdd = new PDO('mysql:host=localhost;dbname=bladuo', 'root', '');
$bdd->exec('SET NAMES utf8');//affichage caractères utf-8 dans la bdd

$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

//enregistrement de l'étudiant dans la bdd
$stmt = $bdd->prepare('INSERT INTO membres(nom,prenom,date_de_naissance,langue_maternelle,langue_etudiee,email,passe)
VALUES(?, ?, ?, ?, ?, ?, ?)');
$success = $stmt->execute(array($name , $firstName , $birthDate, $languageM , $languageE , $email,$password1_sha1));

if($success)
{
header('Location: Index.php');
}else

{
echo "INSERT a echouer!!";
exit();
}
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
}

}

}else
{
print "<span style=\"color:red;\">Les mots de passe ne sont pas identiques</span>";
exit();
}

}else
{
print "<span style=\"color:red;\">une des variables nest pas set</span>";
}

}

?>

关于php - 用户存在检查器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24825496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com