我有点坚持使用更新查询。我已经试过替代语法,但我仍然得到同样的错误。您的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中构建它。 –