簡體   English   中英

嘗試將鍵值插入MySQL表時出錯

[英]Error trying to insert key value into a MySQL table

我在嘗試將一個鍵值(我生成的)插入表(​​jml_acymailing_subscriber)時遇到問題。

$generateKey = md5(substr($email[1],0,strpos($email[1],'@')).rand(0,10000000));
$subid = 3603;
$sql2 = "UPDATE jml_acymailing_subscriber SET key='$generateKey', WHERE subid='$subid'";
$result2 = mysql_query($sql2,$con) or trigger_error(mysql_error(),E_USER_ERROR);

關鍵類型是:

TYPE -->  varchar(250)  
ORDENATION --> utf8_general_ci
NULL --> yes
DEFAULT --> NULL

這是我得到的錯誤:

Fatal error: 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 
'key='15e3e092aa8672a6f7ad3e8a5a1db537', WHERE subid='3603'' at line 1 in 
/public_html/bootstrap3/donarAltaCatala.php on line 136

插入useridnamecreated或其他任何值都沒有問題。 誰知道問題出在哪里? 我是從PHP / SQL開始的......

謝謝! 我真的很感激!

key是mysql中的reserverd word,所以可以使用反引號

$sql2 = "UPDATE jml_acymailing_subscriber SET `key`='$generateKey' WHERE subid='$subid'";

http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

兩件事情;

KEYMySQL中保留字 ,因此要將其用作字段/表名,需要使用反引號(`)引用

...和...

"UPDATE jml_acymailing_subscriber SET key='$generateKey', WHERE subid='$subid'"
                                                        ^ erroneous comma

更正,這將導致;

"UPDATE jml_acymailing_subscriber SET `key`='$generateKey' WHERE subid='$subid'"

key='$generateKey'之后刪除,使它看起來像:

"UPDATE jml_acymailing_subscriber SET key='$generateKey' WHERE subid='$subid'";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM