[英]mysql “insert into” SQL syntax error problem
這是PHP代碼:
$stringquery = "INSERT INTO sikurim(name, title, desc, category, subcategory)
VALUES ('$contact', '$heading','$comments', '$catF', '$catS' ) ";
mysql_query($stringquery) or die(mysql_error());
而且我得到了錯誤:
您的SQL語法有誤; 檢查與您的MySQL服務器版本相對應的手冊以獲取正確的語法,以在第1行的'desc,category,subcategory)VALUES('jhjh','fffff','fffff','2','4')'附近使用
我找不到代碼有什么問題,有人可以幫忙嗎?
DESC
是保留的MySQL關鍵字 。 您需要將其括在反引號中:
$stringquery = "INSERT INTO sikurim(name, title, `desc`, category, subcategory) VALUES ('$contact', '$heading','$comments', '$catF', '$catS' )";
您應該轉義每個值。 使用mysql_escape_string http://www.php.net/manual/zh/function.mysql-escape-string.php
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.