以下代码是我的ajax通知系统的一部分,由于某种原因,它只能工作50%。当我调用代码时,它会运行,然后回显为success
或remove
,但似乎没有更改数据库值。任何原因?我试图把我的列名放在引号中,但是回显是错误的。请帮忙,谢谢!PHP更新将无法正确更新数据库
<?php
require_once('.conf.php');
$notid = mysql_real_escape_string($_GET['notification_id']);
$username = mysql_real_escape_string($_SESSION['uname']);
$action = mysql_real_escape_string($_GET['action']);
if ($action == 'add') {
$insert = mysql_query("UPDATE updates SET object_fav = '1' WHERE username = '$username' AND id = '$notid'") or die('Could not connect: ' . mysql_error());
echo 'success';
} elseif($action == 'sub') {
$remove = mysql_query("UPDATE updates SET object_fav = '0' WHERE username = '$username' AND id = '$notid'") or die('Could not connect: ' . mysql_error());
echo 'remove';
} else {
echo 'error';
}
?>
我知道这是不是JavaScript的,我检查了网络选项卡,并发送正确的价值观。
那么,如果查询出错,你的'die()'调用就会被触发。 'echo mysql_affected_rows();''成功/移除''。更可能的是,你只是没有匹配任何行,因为'$ username'或'$ notid'没有包含你期望的内容 – 2012-03-13 01:55:48
@michael在php – 2012-03-13 02:01:10
以上的更高嗯,原来我上传了错误的版本这不包括'session_start()'。愚蠢的我...你是对的michael – 2012-03-13 02:08:56