简体   繁体   English

我不明白为什么出现Statement :: execute()错误?

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

I've a error in my code but I do not find my error... Can you help me please ? 我的代码中有错误,但没有找到我的错误...能帮我吗? here is my code : 这是我的代码:

$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>

And this is the error : 这是错误:

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...

Thank in advance for your help. 预先感谢您的帮助。

Try this instead: 尝试以下方法:

 $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');

Might be this will help you 可能会帮到您

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

In this statement 在此声明中

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

I assume that the first field you pass '' to is a auto increment field something like id . 我假设您将''传递给的第一个字段是一个自动递增字段,类似于id

Becasue you dont pass a field list to the query, you are also asking MySQL to work out what fields to add the data to automatically and it will do that by looking at the schema and getting field names for that table in the order they are stored in the schema. 因为您没有将字段列表传递给查询,所以您还要求MySQL找出要自动添加数据的字段,这将通过查看模式并按存储顺序获取该表的字段名称来完成在架构中。 This can be dangerous as it is quite possible for someone else to change the order that they are stored in, in the schema. 这可能很危险,因为其他人很有可能在架构中更改其存储顺序。

So it is better to add the field names that you want to insert into the query. 因此,最好将要插入的字段名称添加到查询中。

MySQL will look after the auto increment field for you, but now it knows what fields it should be inserting data into from your VALUE list. MySQL将为您照顾自动递增字段,但现在它知道应该从VALUE列表中将数据插入到哪些字段中。

So use :- 所以用:-

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM