2014-03-07 99 views
0

我一直在absolutley掛上這個。MYSQLI調試問題

我正在對我的腳本進行調試。我試圖插入到我的數據庫,但一切運行良好,現在的錯誤。數據庫中沒有輸入內容。好了,所以我強迫一些錯誤,像這樣的報告:

ini_set('display_errors',1); 
error_reporting(E_ALL); 
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); 

我得到了一些偉大的信息&通常這部分是快,但我不能完全得到什麼是錯的。

Fatal error: Uncaught exception 'mysqli_sql_exception' with message '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 'explain,date_added) VALUES('Budget','','','Trading','',now()' at line 1' in upload/inventory_list.php:74 Stack trace: #0 upload/inventory_list.php(74): mysqli_query(Object(mysqli), 'INSERT INTO pro...') #1 {main} thrown in upload/inventory_list.php on line 74

有問題的行是:

$sqls = "INSERT INTO products (product_name,price,details,category,explain,date_added) 
       VALUES('$product_name','$price','$details','$category','$explain',now())"; 

$result = mysqli_query($db_conx,$sqls); 

我從什麼我從我的典型的調試得到正確的路線,但我似乎無法追蹤它。任何幫助是極大的讚賞。

回答

0

是的,你必須在查詢

$sqls = "INSERT INTO products (product_name,price,details,category,explain,date_added) 
       VALUES('$product_name','$price','$details','$category','$explain',now())"; 

明顯的錯誤應該是

$sqls = "INSERT INTO products (product_name,price,details,category,`explain`,date_added) 
       VALUES('$product_name','$price','$details','$category','$explain',now())"; 

解釋是保留關鍵字,以便使用反引號爲

+0

哦男孩。我不相信我忘了。我會更改名稱本身。可能派上用場的東西是未來用戶的參考。你有一個保留關鍵詞列表作爲指導。再次感謝!我不敢相信我花了很多時間試圖弄清楚這一點。 – user3135730

+1

這裏https://dev.mysql.com/doc/refman/5.5/en/reserved-words.html –

+1

是的,檢查@ShankarDamodaran手冊。 –