[英]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, :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))");
// I think u missed one parathesis at the last thats it ^
在此聲明中
$updt=$connect->prepare("INSERT INTO utilisateurs
VALUES ('',:nom, :prenom, :email,
:identifiant, MD5(:mdp)");
我假設您將''
傳遞給的第一個字段是一個自動遞增字段,類似於id
。
因為您沒有將字段列表傳遞給查詢,所以您還要求MySQL找出要自動添加數據的字段,這將通過查看模式並按存儲順序獲取該表的字段名稱來完成在架構中。 這可能很危險,因為其他人很有可能在架構中更改其存儲順序。
因此,最好將要插入的字段名稱添加到查詢中。
MySQL將為您照顧自動遞增字段,但現在它知道應該從VALUE列表中將數據插入到哪些字段中。
所以用:-
$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.