您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在'repeat ='week',location ='Patowmack Farm'附近使用正确的语法,在第1行找到location_link ='http://maps.googl'
我继续为我的更新脚本(上面显示)和我的插入脚本收到此消息。我找不到为什么这样做!有人可以提供帮助吗?
我的更新代码:
foreach($_POST['enabled'] as $key => $value ) {
$key = mysql_real_escape_string($key);
if ($_POST['delete'][$key]=='1') {
mysql_query("DELETE FROM upcoming WHERE id='$key'") or die(mysql_error());
}
else {
$title = mysql_real_escape_string($_POST['title'][$key]);
$date = mysql_real_escape_string(($_POST['date'][$key]));
$repeat = mysql_real_escape_string($_POST['repeat'][$key]);
$group = mysql_real_escape_string($_POST['group'][$key]);
$group_link = mysql_real_escape_string($_POST['group_link'][$key]);
$location = mysql_real_escape_string($_POST['location'][$key]);
$location_link = mysql_real_escape_string($_POST['location_link'][$key]);
$notes = mysql_real_escape_string($_POST['notes'][$key]);
$enabled = mysql_real_escape_string($_POST['enabled'][$key]);
mysql_query("UPDATE upcoming SET title = '$title', date = '$date', repeat = '$repeat', location = '$location', location_link = '$location_link', group = '$group', group_link = '$group_link', notes = '$notes', enabled = '$enabled' WHERE id = '$key' LIMIT 1") or die(mysql_error());
}
}
答案 0 :(得分:6)
您是否尝试将查询更改为:
mysql_query("UPDATE `upcoming` SET `title` = '$title', `date` = '$date', `repeat` = '$repeat', `location` = '$location', `location_link` = '$location_link', `group` = '$group', `group_link` = '$group_link', `notes` = '$notes', `enabled` = '$enabled' WHERE `id` = '$key' LIMIT 1") or die(mysql_error());
编辑:正如其他人所说的那样;你正在使用保留字。我建议总是使用`符号。 (对于大多数键盘,可以在左上角找到:在转义键下方,在标签键上方,在数字1键的左侧。)
答案 1 :(得分:3)
GROUP
和REPEAT
是MySQL中的保留关键字,因此您必须使用反引号“转义”它:
`group` = '$group'
`repeat` = '...'
此外我在这里做了一个假设,但你不应该在引号中包含$key
,因为它是一个整数值。还要确保通过执行int($key)
键入将其强制转换为int。
答案 2 :(得分:0)
repeat是MySQL使用后退标记repeat
中的关键字来使用它。
答案 3 :(得分:0)
重复是mySQL保留字:http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
尝试使用反引号围绕您的列名。