2013-04-23 28 views
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"]); 

由於某些原因,它更新num_reports與2,所以如果它是1它將變成3,然後5等等。我看不出問題在哪裏。

+0

廣告構造函數調用report_ad()方法嗎? – 2013-04-23 10:31:07

+0

不..不是 – 2013-04-23 10:35:22

+0

看在瀏覽器控制檯....是多個Ajax請求? – charlietfl 2013-04-23 10:40:18

回答

1

幫助我們幫助您:

  • 如果手動執行查詢什麼:當錯誤發生追查?還有+2? (每當被重新設置時,存儲過程就會遞增)?
  • 多次調用funktion嗎? ('[email protected]','message');如果您是新手,需要進行php調試,

是不好的做法,但速度很快。 (對於簡單的非基於對象的日誌記錄,也檢查file_put_content())。

另外,也沒有你之後

var aid = {$smarty.get.aid} 

缺少semicolone電賀

編輯:不確定,如果查詢()做一份聲明,或直接運行的查詢?在這種情況下,查詢()和執行()將是您啤酒尋找的兩倍。

+0

中確切地看到它的調用位置如果手動執行查詢,它將僅使用+1正確更新它。 如果我通過終端執行'curl -X PUT http:// www.domain.dk/reportad/43 /',它將更新爲+2,因此它必須與腳本有關。 – 2013-05-21 06:57:13

+0

@MortenHagh我編輯了我的答案。 – 2013-05-21 07:36:07

+0

我沒有執行準備好的聲明!我將其改爲準備好的聲明,瞧!有用!謝謝! – 2013-05-21 07:50:11