我的PHP CODE出错了,错误是:
警告:PDOStatement :: execute():SQLSTATE [HY093]:参数号无效:参数未在第91行的C:\ wamp \ www \ modding-gaming.com \ check_register.php中定义
我不明白..
我的PHP代码:(我是法国人)
<?php
include('includes/connect_db.php');
if (isset($_POST['create']))
{
if ((isset($_POST['nom'])) &&
(!empty($_POST['nom'])) &&
(isset($_POST['prenom'])) &&
(!empty($_POST['prenom'])) &&
(isset($_POST['pseudo'])) &&
(!empty($_POST['pseudo'])) &&
(isset($_POST['age'])) &&
(!empty($_POST['age'])) &&
(isset($_POST['email'])) &&
(!empty($_POST['email'])) &&
(isset($_POST['about'])) &&
(!empty($_POST['about'])) &&
(isset($_POST['mdp'])) &&
(!empty($_POST['mdp'])) &&
(isset($_POST['mdp_ok'])) &&
(!empty($_POST['mdp_ok'])))
{
extract($_POST);
if (strlen($_POST['pseudo']) < 4 || strlen($_POST['pseudo'] > 15))
{
echo 'Le pseudo doit contenit 4 à 15 caracteres.';
exit();
}
else {
$req = $bdd->prepare('SELECT * FROM users WHERE pseudo = ?');
$req->execute(array($_POST['pseudo'])) or die(print_r($req->errorInfo()));
$compte_pseudo = $req->rowCount();
if ($compte_pseudo > 0)
{
echo 'Le pseudo est deja utilise.';
exit();
}
}
if ($age< 10)
{
echo 'Vous devez avoir 10ans ou plus pour pouvoir vous inscrire.';
} else if ($age >= 100)
{
echo 'Veuillez rentrer un age correct.';
exit();
} else {
$req = $bdd->prepare('SELECT * FROM users WHERE email = ?');
$req->execute(array($email));
$compte_email = $req->rowCount();
if ($compte_email > 0)
{
echo 'L\'email est deja utilisee.';
exit();
}
if ($sexe != 'Homme' && $sexe != 'Femme')
{
echo 'Veuillez definir votre sexe.';
exit();
}
if (strlen($_POST['mdp']) < 5 || strlen($_POST['mdp_ok'] > 20))
{
echo 'Le mot de passe doit contenir 5 a 20 caracteres.';
} else if (!($_POST['mdp'] == $_POST['mdp_ok']))
{
echo 'Les mots de passe doivent etre identique.';
} else
{
$ip = $_SERVER['REMOTE_ADDR'];
$date_creation = date("d/m/Y",time());
$hash_mdp = sha1($mdp);
$req = $bdd->prepare('INSERT INTO users(pseudo, password, sexe, prenom, nom, age, email, grade, about, ip, created)
VALUES(:pseudo, :mdp, :sexe, :prenom, :nom, :age, :email, :grade, :about, :ip, :date_creation)') or die(print_r($req->errorInfo()));
$req->execute(array(
'pseudo' => $pseudo,
'password' => $hash_mdp,
'sexe' => $sexe,
'prenom' => $prenom,
'nom' => $nom,
'age' => $age,
'email' => $email,
'grade' => 'Administrateur',
'about' => $about,
'ip' => $ip,
'created' => $date_creation
)) or die(print_r($req->errorInfo()));
}
}
} else
{
echo 'Veuillez remplir tous les champs.';
}
} //结束
谢谢你!
第91行:
)) or die(print_r($req->errorInfo()));
答案 0 :(得分:0)
在您发送的数组参数之前添加 :
冒号。这样做..
$req->execute(array(
':pseudo' => $pseudo,
':password' => $hash_mdp, <----- Should be :mdp instead of :password
':sexe' => $sexe,
---^
为所有按键执行此操作。
答案 1 :(得分:0)
$req = $bdd->prepare('INSERT INTO users(pseudo, password, sexe, prenom, nom, age, email, grade, about, ip, created)
VALUES(:pseudo, :mdp, :sexe, :prenom, :nom, :age, :email, :grade, :about, :ip, :date_creation)') or die(print_r($req->errorInfo()));
$req->execute(array(
':pseudo' => $pseudo,
':mdp' => $hash_mdp,
':sexe' => $sexe,
':prenom' => $prenom,
':nom' => $nom,
':age' => $age,
':email' => $email,
':grade' => 'Administrateur',
':about' => $about,
':ip' => $ip,
':date_creation' => $date_creation
)) or die(print_r($req->errorInfo()));
}