正如标题所说,我不明白这个问题的错误:
$query = "UPDATE ".$SupportFaqTable." a
INNER JOIN ".$SupportRateFaqTable." b
ON b.faq_id=a.id
SET
a.rate=CASE WHEN b.updated='1' THEN ROUND(((a.num_rate * a.rate - b.rate) + ?)/(a.num_rate),2) ELSE ROUND(((a.rate + ?)/(a.num_rate+1),2) END,
a.num_rate=CASE WHEN b.updated='1' THEN a.num_rate ELSE a.num_rate+1 END,
b.updated='0'
WHERE a.id=?";
这是$query
:
UPDATE razorphyn_support_faq a
INNER JOIN razorphyn_support_faq_rate b
ON b.faq_id=a.id
SET
a.rate=CASE WHEN b.updated='1' THEN ROUND(((a.num_rate * a.rate - b.rate) + ?)/(a.num_rate),2) ELSE ROUND(((a.rate + ?)/(a.num_rate+1),2) END,
a.num_rate=CASE WHEN b.updated='1' THEN a.num_rate ELSE a.num_rate+1 END,
b.updated='0'
WHERE a.id=?
修改
显式错误:
["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 'WHERE a.id=?' at line 8"]
修改
这是完整的php函数:
$rate=(is_numeric($_POST['rate']))? $_POST['rate']:0;
$GT86=(is_numeric($_POST['idBox']))? $_POST['idBox']/3823:0;
if($GT86>10 && $rate>0){
$mysqli = new mysqli($Hostname, $Username, $Password, $DatabaseName);
$stmt = $mysqli->stmt_init();
$query = "INSERT INTO ".$SupportRateFaqTable." (`faq_id`,`usr_id`,`rate`) VALUES (?,?,?) ON DUPLICATE KEY UPDATE `rate`=?,`updated`='1'";
$stmt->prepare($query)
$stmt->bind_param('iiii',$GT86,$_SESSION['id'],$rate,$rate)
$stmt->execute()
$query = "UPDATE ".$SupportFaqTable." a
INNER JOIN ".$SupportRateFaqTable." b
ON b.faq_id=a.id
SET
a.rate=CASE WHEN b.updated='1' THEN ROUND(((a.num_rate * a.rate - b.rate) + ?)/(a.num_rate),2) ELSE ROUND(((a.rate + ?)/(a.num_rate+1),2) END,
a.num_rate=CASE WHEN b.updated='1' THEN a.num_rate ELSE a.num_rate+1 END,
b.updated='0'
WHERE a.id=?";
$stmt->prepare($query)
$stmt->bind_param('iii', $rate,$rate,$GT86)
$stmt->execute()
echo json_encode(array(0=>'Voted'));
}
else
echo json_encode(array(0=>'Invalid Information'));
exit();
这些是表格:
CREATE TABLE IF NOT EXISTS `razorphyn_support_faq` (
`id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
`question` VARCHAR(200) NOT NULL,
`answer` VARCHAR(2000) NOT NULL,
`position` INT(4) UNSIGNED NOT NULL DEFAULT 0,
`active` ENUM('0','1') NOT NULL DEFAULT '1',
`num_rate` INT(8) UNSIGNED NOT NULL DEFAULT 0,
`rate` DECIMAL(4,2) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY(`question`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=15;
CREATE TABLE IF NOT EXISTS `razorphyn_support_faq_rate`(
`id` BIGINT(15) UNSIGNED NOT NULL AUTO_INCREMENT,
`faq_id` INT(5) UNSIGNED NOT NULL,
`usr_id` BIGINT(15) UNSIGNED NOT NULL,
`rate` DECIMAL(4,2) UNSIGNED NOT NULL DEFAULT 0,
`updated` ENUM('0','1') NOT NULL DEFAULT '0',
`note` VARCHAR(200) ,
PRIMARY KEY (`id`),
UNIQUE KEY(`faq_id`,`usr_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=15;
答案 0 :(得分:0)
我认为你错过了一个闭幕式,在这里:
... ELSE ROUND(((a.rate + ?)/(a.num_rate+1),2) END,
看起来添加一个关闭paren将解决问题:
... ELSE ROUND(((a.rate + ?)/(a.num_rate+1) ) ,2) END,
^............. add ")" here