2013-06-12 39 views
-1

我已經傾注了這一點,無法找到可能導致錯誤的原因。有什麼建議麼?在INSERT上獲取MySQL錯誤代碼1064

$sql = "INSERT INTO users (`id`, `username`, `password`, `firstname`, 
     `lastname`, `photo`, `mobile`, `fax`, `bday`, `homeadd`, `city`, 
     `state`, `zip`, `mailingadd`, `altfax`, `altphone`, `email`, 
     `emailpass`, `website`, `bio`, `designations`, `photo2`, `type`, 
     `confirmed_email`, `registered_on`, `disabled`, `admin_disabled`) 
     VALUES (NULL, $username, MD5('$password'), $firstname, $lastname, 
     '', 'test', '', '', '', '', '', '', '', '', '', $email, '', '', '', '', 
     '', 'agent', '1', NOW(), $disabled, 0)";` 
+2

重構你的代碼請給我們完整的錯誤信息。 –

回答

0

您的變量仍然應該用單引號引起來。每次插入'$variable'時,請在其周圍單引號。

0

你應該在你的個人價值添加引號:

$sql = "INSERT INTO users (id,username,password,firstname,lastname,photo,mobile,fax,bday,homeadd,city,state,zip,mailingadd,altfax,altphone,email,emailpass,website,bio,designations,photo2,type,confirmed_email,registered_on,disabled,admin_disabled) VALUES (NULL, '$username', MD5('$password'), '$firstname', '$lastname', '', 'test', '', '', '', '', '', '', '', '', '', '$email', '', '', '', '', '', 'agent', '1', NOW(), $disabled, 0)"; 
+0

現在它說列計數與行計數不匹配...即使它顯然確實... –

+0

您是否複製粘貼此答案?語法是這個答案是不正確的。你還需要在''$ disabled''附近加單引號。 –

+0

如果禁用爲布爾型或INT型,則不會「需要」引用$ disabled,但我同意如果內容不確定,則會推薦它。我還建議斯坦尼斯拉夫的答案,因爲它可以確保任何單引號已經財產逃脫,這可能是你的持續問題的原因。 –

0

你不是引用變量:

$sql  = "INSERT INTO users 
(`id`, `username`, `password`, `firstname`, `lastname`, `photo`, `mobile`, `fax`, `bday`, `homeadd`, `city`, `state`, `zip`, `mailingadd`, `altfax`, `altphone`, `email`, `emailpass`, `website`, `bio`, `designations`, `photo2`, `type`, `confirmed_email`, `registered_on`, `disabled`, `admin_disabled`) VALUES 
(NULL, '$username', MD5('$password'), '$firstname', '$lastname', '', 'test', '', '', '', '', '', '', '', '', '', '$email', '', '', '', '', '', 'agent', '1', NOW(), '$disabled', 0)"; 

我真的建議從mysql_越來越遠*功能,因爲它們」不推薦使用,不適用於將來的版本。如果您使用PDO或MySQLi,則可以使用綁定函數,因此您不必擔心引用值。