MySQL 更新时出现语法错误
MySQL syntax error when updating
在此脚本中找不到问题:
$delhash = array();
$resultxx = mysqli_query($datba1,"SELECT htag
FROM wall_hashtags
WHERE publicat='$permid'") or die('Error1');
while(list($dht) = mysqli_fetch_row($resultxx)) {
$delhash[] = $dht;
}
以下更新不起作用:
$result_update = mysqli_query($datba1,"UPDATE wall_hashtags SET
numbr=numbr-1 WHERE htag IN (".implode(",", $delhash).")")
die(mysqli_error($datba1));
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 'first,second,third' at line 1
数组:
echo '<pre>'; print_r($delhash); echo '</pre>';
Array
(
[0] => first
[1] => second
[2] => third
)
请确保您使用 IN()
子句和 varchar
值进行更新。查看 this 了解更多详情。
所以你应该用'
包裹它。
$result_update = mysqli_query($datba1,"UPDATE wall_hashtags SET
numbr=numbr-1 WHERE htag IN ('".implode("','", $delhash)."')")
or die(mysqli_error($datba1));
在此脚本中找不到问题:
$delhash = array();
$resultxx = mysqli_query($datba1,"SELECT htag
FROM wall_hashtags
WHERE publicat='$permid'") or die('Error1');
while(list($dht) = mysqli_fetch_row($resultxx)) {
$delhash[] = $dht;
}
以下更新不起作用:
$result_update = mysqli_query($datba1,"UPDATE wall_hashtags SET
numbr=numbr-1 WHERE htag IN (".implode(",", $delhash).")")
die(mysqli_error($datba1));
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 'first,second,third' at line 1
数组:
echo '<pre>'; print_r($delhash); echo '</pre>';
Array
(
[0] => first
[1] => second
[2] => third
)
请确保您使用 IN()
子句和 varchar
值进行更新。查看 this 了解更多详情。
所以你应该用'
包裹它。
$result_update = mysqli_query($datba1,"UPDATE wall_hashtags SET
numbr=numbr-1 WHERE htag IN ('".implode("','", $delhash)."')")
or die(mysqli_error($datba1));