時,這是我的代碼:錯誤插入SQL表PHP
function function() {
$isbn = $_REQUEST["isbn"];
$price = $_REQUEST["price"];
$cond = $_REQUEST["cond"];
$con = mysql_connect("localhost","my_usernam", "password");
if (!$con) die('Could not connect:' . mysql_error());
mysql_select_db("my_database",$con);
$sql="INSERT INTO 'Books' (isbn, price, condition)
VALUES ('$isbn','$price','$cond')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con);
return "It works";
但運行時,它會導致:
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 ''Books' (isbn, price....
任何人都知道爲什麼發生這種情況?在反引號,不是報價
如果你有一個SQL錯誤,最好的辦法通常是輸出你試圖在執行和嘗試「幹」查詢SQL工作表(如在phpMyAdmin中);如果它不能在那裏工作,你的問題是在SQL域中,你可以將PHP和連接問題弄糊塗了。 – lotsoffreetime 2010-08-05 19:42:00