我不明白为什么我've Statement::execute()错误


I don't understand why I've Statement::execute() error?

我的代码有一个错误,但我没有找到我的错误…你能帮我一下吗?下面是我的代码:

$updt=$connect->prepare("INSERT INTO utilisateurs VALUES ('',:nom, :prenom, :email, :identifiant, MD5(:mdp)");
$updt->execute(array('nom'=>$nom,
'prenom'=>$prenom,
'email'=>$email,
'identifiant'=>$identifiant,
'mdp'=>$motDePasse
));
header('./gestion-utilisateur.php');</pre>

错误如下:

Warning: PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2 in...

提前感谢您的帮助

也许这对你有帮助

$updt=$connect->prepare("INSERT INTO utilisateurs VALUES ('',:nom, :prenom, :email, :identifiant, MD5(:mdp))");
// I think u missed one parathesis at the last thats it                                                    ^ 

试试这个:

 $updt=$connect->prepare("INSERT INTO utilisateurs VALUES ('',:nom, :prenom, :email, :identifiant, :mdp)");
$updt->execute(array('nom'=>$nom,
'prenom'=>$prenom,
'email'=>$email,
'identifiant'=>$identifiant,
'mdp'=>MD5($motDePasse)
));
header('./gestion-utilisateur.php');

在此语句中

$updt=$connect->prepare("INSERT INTO utilisateurs 
                         VALUES ('',:nom, :prenom, :email, 
                                 :identifiant, MD5(:mdp)");

我假设你传递给''的第一个字段是一个自动递增字段,比如id

因为你没有将字段列表传递给查询,你也要求MySQL自动计算出要添加数据的字段,它将通过查看模式并根据它们在模式中存储的顺序获取表的字段名来完成。这是很危险的,因为其他人很可能改变它们在模式中的存储顺序。

所以最好添加您想要插入到查询中的字段名。

MySQL将为你照看auto increment字段,但是现在它知道应该从VALUE列表中插入数据到哪些字段。

所以使用:-

$updt=$connect->prepare("INSERT INTO utilisateurs 
                         (nom,prenom,email,identifiant,mdp) 
                         VALUES (:nom, :prenom, :email, 
                                 :identifiant, MD5(:mdp)");