更新脚本double计数器



我有这个小脚本来更新一个报表计数器

    /*********************************
     * Report an ad as inappropriate
     * This happens when a user click
     * the "Report ad" link on the ad
     * view page.
     * 
     * The ad can then be reviewed
     * and disabled.
     * 
     * @param int | The ad id
     *********************************/
    function report_ad($aid) {
        $row = $this->db->dbh->query('UPDATE '. $this->config->db_prefix .'_adverts SET been_reported = 1, num_reports = num_reports + 1 WHERE aid = '.$aid.'');
        $row->execute();        
    }
和这个jQuery来处理链接点击
$("#report-ad").click(function(){
   var conf = confirm("Do you want to report this ad as inappropriate?");
   var aid = {$smarty.get.aid}
   if(conf == true) {
     $.ajax({
       url: 'reportad.php',
       type: 'post',
       data: {literal}{aid: aid}{/literal},
       success: function(data) {
          alert("The ad has been reported as inappropriate");
       },
       error: function(data) {
          alert("An error occured");
       }
     });
  }
  return false;
});

reportad.php只包含这个:

$adverts = new Adverts();
$adverts->report_ad($_POST["aid"]);
由于某种原因,

将num_reports更新为2,所以如果它是1,它将变为3,然后变为5,依此类推。我看不出问题在哪里

帮助我们帮助您:跟踪错误发生的位置:

  • 如果您手动执行查询怎么办?+ 2 ?(设置been_reporting时存储过程递增)?
  • 函数是否被多次调用?如果您是PHP调试新手,

    邮件("me@host.com"、"消息");

是不好的做法,但做起来很快。(也检查file_put_content()以获取简单的非基于对象的日志记录)。

还有,你是不是在

后面少了一个分号?
var aid = {$smarty.get.aid}

打招呼

编辑:不确定如果query()是一个准备好的语句,还是直接运行查询?在这种情况下,query()和execute()将是您寻找的两倍。

最新更新