我正在为网站创建注册页面。当我提交表格的时间甚至比指定的长度更短时,我直接进入索引页面。数据也没有保存在我的数据库中。有人知道为什么会这样吗?以下代码来自名为register.php的脚本
<?php
if (isset($_POST['submit']))
{
//on récupère les données entrées
$name = $_POST['userName'];
$firstName = $_POST['firstName'];
$birthDate = $_POST['day'].':'.$_POST['month'].':'.$_POST['year'];
$languageM = $_POST['langueM']; //langue maternelle
$languageE = $_POST['langueE']; //langue étudiée
$email = $_POST['mailInput'].'@'.$_POST['schools'];
$Password1 = $_POST['Password1'];
$Password2 = $_POST['Password2'];
if($name&&$firstName&&$birthdate&&$languageM&&$languageE&&$email&&$Password1&&$Password2)
{
//hashage du mot de passe
$password1_md5 = md5($Password1);
$password2_md5 = md5($Password2);
if ($Password1==$Password2)
{
// taille du nom ou du prénom
if (strlen($userName)>25||strlen($firstName)>25)
{
echo "Nom ou prénom trop long !";
}
else
{
//check password length
if (strlen ($password1)>25 || strlen ($password1)<6)
{
echo "Le mot de passe doit etre entre 6 et 25 caractères";
}
else
{
//connection à la bdd
try
{
$bdd = new PDO('mysql:host=localhost;dbname=test', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
//enregistremnt de l'étudiant dans la bdd
$bdd->exec('INSERT INTO nouveau_membre(nom,prenom,date_de_naissance,langue_maternelle,langue_etudiee,email,passe)
VALUES($name , $firstName , $birthDate, $languageM , $languageE , $email, $password1_md5)');
}
}
}
else echo "Les mots de passe ne sont pas identiques";
}
}
header('Location: Index.php');
?>
这是我的表格
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Accueil</title>
<link rel="stylesheet" href="../css/bootstrap.css">
<link rel="stylesheet" href="../css/">
</head>
<body>
<?php include("header.html"); ?>
<div id="formulaireInscription">
<h3 id="titreIncrivez">Inscrivez-vous!</h3>
<form action="Register.php" method="post" role="form">
<div class="form-group">
<div id="renseignementgenerale" class="form-group">
<label for="userName"><br />Nom:
<input type="text" class="form-control" name="userName" placeholder="Entrez votre nom" required="required"></label><br />
<label for="firstName">Prénom:</label>
<input type="text" class="form-control" name="firstName" placeholder="Entrez votre prénom" required="required">
<div class="form-group" id="birthdate">
<label>Date de naissance:</label>
<label for="dayInput">Jour</label>
<select name="day">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<label for"monthInput">Mois</label>
<select name="month">
<option value="month1">Janvier</option>
<option value="month2">Février</option>
<option value="month3">Mars</option>
<option value="month4">Avril</option>
<option value="month5">Mai</option>
<option value="month6">Juin</option>
<option value="month7">juillet</option>
<option value="month8">Aout</option>
<option value="month9">Septembre</option>
<option value="month10">Octobre</option>
<option value="month11">Novembre</option>
<option value="month12">Décembre</option>
</select>
<label for"yearInput">Année</label>
<select name="year">
<option value="year1">2014</option>
<option value="year2">2013</option>
<option value="year3">2012</option>
<option value="year4">2011</option>
<option value="year5">2010</option>
<option value="year6">2009</option>
<option value="year7">2008</option>
<option value="year8">2007</option>
<option value="year9">2006</option>
<option value="year10">2005</option>
<option value="year11">2004</option>
<option value="year12">2003</option>
<option value="year13">2002</option>
<option value="year14">2001</option>
<option value="year15">2000</option>
<option value="year16">1999</option>
<option value="year17">1998</option>
<option value="year18">1997</option>
<option value="year19">1996</option>
<option value="year20">1995</option>
<option value="year21">1994</option>
<option value="year22">1993</option>
<option value="year23">1992</option>
<option value="year24">1991</option>
<option value="year25">1990</option>
</select>
</div>
<div class="form-group" id="langueM">
<label>Langue maternelle:</label>
<select name="langueM">
<option value="langue1">Français</option>
<option value="langue2">Anglais</option>
<option value="langue3">Espagnol</option>
</select>
</div>
<div class="form-group" id="langueE">
<label>Langue étudiée:</label>
<select class="langueE">
<option value="langue1">Français</option>
<option value="langue2">Anglais</option>
<option value="langue3">Espagnol</option>
</select>
</div>
</div>
<label >Adresse email:</label>
<div>
<div class="mailliste">
<input name="mailInput" type="text" placeholder="Entrez votre email" required="required">@
<select name="schools" onchange="VerifListe();">
<option value="valeur1">rms.fr</option>
<option value="valeur2">icade.es</option>
<option value="valeur3">esb.de</option>
</select>
</div><br>
</div>
</div>
<div class="form-group">
<label for="inscriptionInputPassword1">Mot de passe:</label>
<input type="password" class="form-control" name="Password1" placeholder="Entrez votre mode passe" required="required"><br>
<input type="password" class="form-control" name="Password2" placeholder="Répétez votre mode passe" required="required">
</div>
<input type="submit" name="submit" value="Inscription"/>
</form>
</div>
</body>
答案 0 :(得分:1)
错别字:
if (isset($_Post['submit']))
^^^^---here
PHP变量区分大小写,这意味着$_Post
是一个未定义的变量。由于永远不会定义$_Post
,因此绕过您的整个表单处理代码块。
尝试
if (isset($_POST['submit']))
代替。然后在php.ini中打开display_errors
和error_reporting
。如果你有这些,你就会被警告使用未定义的变量。
答案 1 :(得分:-1)
MD5不再安全,所以当你有机会改变它
<?php
if (isset($_POST['submit']))
{
//on récupère les données entrées
$name = $_POST['userName'];
$firstName = $_POST['firstName'];
$birthDate = $_POST['day'].':'.$_POST['month'].':'.$_POST['year'];
$languageM = $_POST['langueM']; //langue maternelle
$languageE = $_POST['langueE']; //langue étudiée
$email = $_POST['mailInput'].'@'.$_POST['schools'];
$Password1 = $_POST['Password1'];
$Password2 = $_POST['Password2'];
//C'est mieux de verifier avec isset()
if(isset($name,$firstName,$birthdate,$languageM,$languageE,$email,$Password1,$Password2))
{
if ($Password1===$Password2)//triple equals more secure
{
//hashage du mot de passe
$password1_md5 = md5($Password1);
$password2_md5 = md5($Password2);
// taille du nom ou du prénom
if (strlen($userName)>25||strlen($firstName)>25)
{
echo "Nom ou prénom trop long !";
exit();//plus la peine de continuer
}
else
{
//check password length
if (strlen ($password1)>25 || strlen ($password1)<6)
{
echo "Le mot de passe doit etre entre 6 et 25 caractères";
exit();//plus la peine de continuer
}
else
{
//connection à la bdd
try
{
$bdd = new PDO('mysql:host=localhost;dbname=test', 'root', '');
//ajoute cette line pour connaitre l'erreur
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//enregistremnt de l'étudiant dans la bdd
$stmt = $bdd->prepare('INSERT INTO nouveau_membre(nom,prenom,date_de_naissance,langue_maternelle,langue_etudiee,email,passe)
VALUES(?, ?, ?, ?, ?, ?, ?)');
$success = $stmt->execute(array($name , $firstName , $birthDate, $languageM , $languageE , $email,$password1_md5));
if($success){
header('Location: Index.php');
}else{
echo "INSERT a echouer!!";
exit();//plus la peine de continuer
}
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
}
}
}
else{
echo "Les mots de passe ne sont pas identiques";
exit();//plus la peine de continuer
}
}else{
echo 'une des variables nest pas set';
}
}