我有點堅持使用更新查詢。我已經試過替代語法,但我仍然得到同樣的錯誤。您的SQL語法有錯誤;檢查...正確的語法使用近「「類別=
$itemName = mysql_real_escape_string($_POST['itemName']);
$itemDescription = mysql_real_escape_string($_POST['itemDescription']);
$itemCategory = mysql_real_escape_string($_POST['itemCategory']);
if(isset($_POST['itemPrice']))
$itemPrice = mysql_real_escape_string($_POST['itemPrice']);
$statement = 'update products set "category = ' .
$itemCategory.', price = "'.
$itemPrice .'", product = "' .
$itemName . '", description = "' .
$itemDescription . '" where id = "' .
$itemId . '"';
if(mysqli_query($db, $statement))
{
$kittehHasError = false;
$message = $itemName . " has been updated successfully.";
}
else
{
$kittehHasError = true;
$message = "Something went wrong: " . mysqli_error($db);
}
<p><? echo $message ?></p>
我收到的錯誤是:
Something went wrong: 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 '"category = games, price = "60.75", product = "Wildstar", description = "Ongoing' at line 1
我在做什麼錯了,我已經設置斷點和所有的值都保持數據和正確的資料,因此我不知道爲什麼查詢是不是?我認爲這可能是因爲描述包含單一e引用,但是,當添加MySQL_real_escape_string()我仍然收到相同的錯誤。
複製結果查詢並直接在SQL客戶端中嘗試它。然後嘗試更改可疑部分,直到它工作。一旦它在那裏工作,你就會知道如何在PHP中構建它。 –