0

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

    /*********************************
     * 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"]);

由于某种原因,它用 2 更新 num_reports,所以如果它是 1,它将变为 3,然后是 5,依此类推。我看不出哪里有问题。

4

1 回答 1

1

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

  • 如果您手动执行查询怎么办?还有+2?(只要设置了 bes_reported,存储过程就会递增)?
  • 函数是否被多次调用?如果您是 php 调试新手,

    邮件('我@host.com','消息');

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

另外,你后面不是少了一个分号吗

var aid = {$smarty.get.aid}

问候

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

于 2013-05-16T20:15:00.553 回答