我有 3 个网页,一个用于登录,一个用于注册,最后一个是主页(索引)。我有 2 个来自登录的变量和 5 个来自注册的变量,所有变量都被发送到主页,因此当我在登录变量中注册时没有值,因此会出现错误“注意未定义的索引” ,当我注册时,也会发生同样的情况,但错误显示了登录的变量。我在谷歌上进行了很多搜索,发现了一个名为 unset 的函数来禁用变量,但没有任何反应。
// Sous WAMP
$bdd = new PDO('mysql:host=localhost;dbname=test exbook;charset=utf8', 'root', '');
$reponse = $bdd->query('SELECT * FROM registration');
$nom = $_POST['nom'];
$birthday = $_POST['birthday'];
$genre = $_POST['genre'];
$email = $_POST['email'];
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
if (isset($nom , $birthday , $genre , $email, $password )) {
unset($nom);
unset($birthday);
unset($genre);
unset($email);
unset($password);
} else {
$req = $bdd->prepare('INSERT INTO registration(`Nom`, `Date de naissance`, `Genre`, `Email`, `Password`) VALUES(?,?,?,?,?)');
$req->execute(array($nom, $birthday, $genre, $email, $password));
}
while ($donnees = $reponse->fetch()) {
echo $donnees['Nom'];
}
$bdd = new PDO('mysql:host=localhost;dbname=test exbook;charset=utf8', 'root', '');
$emailsignup = $_POST['emailsignup'];
if (isset($emailsignup)) {
unset($emailsignup);
} else{
$bdd1 = $bdd->query('SELECT * FROM registration WHERE $emailsignup');
}
感谢您阅读本文并尽力提供帮助。祝你今天过得愉快 :)
倚天杖