我正在尝试此代码,但它无效。
主要问题在于这些变量或底部给出的脚本。
<?PHP
$upVote1 = "UPDATE facerate SET votes = votes + 1 WHERE Picture = '".$idOptain1."'";
$upVote2 = "UPDATE facerate SET votes = votes + 1 WHERE Picture = '".$idOptain2."'";
$upIgnore1 = "UPDATE facerate SET ignores = ignores + 1 WHERE Picture = '".$idOptain2."'";
$upIgnore2 = "UPDATE facerate SET ignores = ignores + 1 WHERE Picture = '".$idOptain1."'";
?>
<img onClick='renderData1()' src="<?php echo $img1['Picture'] ?>" />
<img onClick='renderData2()' src="<?php echo $img2['Picture'] ?>" />
<!-- £££££££££££££££ SCRIPT HERE ££££££££££££££ -->
<script>
function renderData1()
{
document.write(<?php mysql_query("$update1, $upIgnore1") or die(mysql_error()); ?>);
};
function renderData2()
{
document.write(<?php mysql_query("$update2, $upIgnore2") or die(mysql_error()); ?>);
};
</script>
答案 0 :(得分:1)
mysql_query不支持多个查询。您需要在每次调用时将其分解为单个查询。
答案 1 :(得分:1)
你应该设置一些Ajax请求来注册用户投票:这可能会让你知道如何做(在这里使用jQuery):
在投票点击事件上执行的Javascript函数:
function upvote_picture(id){
$.ajax({
type: 'POST',
url: 'vote.php',
dataType: 'json',
data: {
picture_id: id
},
success: function (data) {
alert(data);
}
});
}
vote.php 档案:
<?php
// Any error or warning in this script will break JSON response !
function send_json($array)
{
header('Content-Type: application/json; charset=utf-8');
echo json_encode($array);
exit();
}
// Add query execution status variables and messages here
$response = array();
$id = !empty($_POST['picture_id']) ? $_POST['pciture_id'] : FALSE;
if($id){
// Do you query here
if ( mysql_query(....)) {
$response['success'] = TRUE;
} else {
$response['success'] = FALSE;
}
} else {
$response['success'] = FALSE;
}
send_json($response);
?>