SQL 'INSERT' 多次插入值而不是一次

SQL 'INSERT' is inserting the value multiple times instead of only one

大家好,我正在制作一个点赞系统,将点赞者和点赞的内容发送到数据库。但事实证明 SQL INSERT 语句做的工作比它应该做的更多......它应该与用户 account_id 一起保存一行,而喜欢的内容是 screenshot_id.但相反,它多次插入相同的值,如下所示:

编号 | account_id | screenshot_id

1 .|.........2.........|......15......

2 .|.........2.........|......15......

3 .|.........2.........|......15......

4 .|.........2.........|......15......

这只是一个示例,这是我在 php 中使用的实际代码:

<?php
    include('connect.php');
    $acc_id = $_POST['acc_id']; //value = 2
    $id = $_POST['id']; //value = 15
    if($id && $acc_id != 0){
        $count = mysqli_num_rows(mysqli_query($connect, "SELECT `id` FROM `screenshot_votes` WHERE `account_id` = '$acc_id' AND `screenshot_id` = '$id';"));
        if($count == 0){ //checking if there is already a vote with those values
            mysqli_query($connect, "INSERT INTO `screenshot_votes` (id,account_id,screenshot_id,vote) VALUES (NULL,'$acc_id','$id','2');");
        //values being insert above
        }
        $row = mysqli_num_rows(mysqli_query($connect, "SELECT `vote` FROM `screenshot_votes` WHERE `screenshot_id` = $id AND `vote` = 2;"));
        echo $row;
    }
?>

所以...我如何让这段代码像这样只插入一次值:

编号 | account_id | screenshot_id

1 .|.........2.........|......15......

更新

这是滑块jquery插件中的onclick事件:

j=function(){
var acc_id = r.accid;
e.each(o,function(t,n){
var r=e(n).children("img:first-child").attr("views");
r||(r=e(n).children("a").find("img:first-child").attr("views"));
o.on("click",".vote",function(e){
var id = $(this).attr('id');
var name = $(this).attr('name');
var dataString = 'id=' + id;
if(name == 'up'){
$('.pos_value.id'+id).fadeIn(100).html('...');
$.ajax({
type: 'POST',
url: 'pages/scripts/up_vote.php',
data: {id: id, acc_id: acc_id},
cache: false,
success: function(html){
$('.pos_value.id'+id).html(html);
$('.vote.pos_vote_enabled.img'+id).css({"background-image": "url(images/icons/pos.png)"});
$('.vote.pos_vote_enabled.img'+id).attr('class', 'pos_vote');
$('.vote.neg_vote_enabled.img'+id).attr('class', 'neg_vote');
}
});
}else{
$('.neg_value.id'+id).fadeIn(100).html('...');
$.ajax({
type: 'POST',
url: 'pages/scripts/down_vote.php',
data: {id: id, acc_id: acc_id},
cache: false,
success: function(html){
$('.neg_value.id'+id).html(html);
$('.vote.neg_vote_enabled.img'+id).css({"background-image": "url(images/icons/neg.png)"});
$('.vote.neg_vote_enabled.img'+id).attr('class', 'neg_vote');
$('.vote.pos_vote_enabled.img'+id).attr('class', 'pos_vote');
}
});
}
return false;
});
if(r){
r=e('<span class="bjqs-views">'+r+'</span>');
r.appendTo(e(n))
}
})
}

所以...我不确定脚本的其余部分是否正确,但我更深入地研究了 google 以获得更多答案并找到了 unbind() 并且它对我有用在 onclick 函数中:

o.unbind().on("click",".vote",function(e){