0

在我发布这个之前,我已经查找了我的问题。所以在这里

我正在使用 ajax 来获取使用 post 的值。但似乎当我将它插入我的数据库时,它会产生重复的条目。这是我的ajax代码

var receiverUserIds = FB.ui({
        method: 'apprequests',
        message: 'Test App',
    },

    function (receiverUserIds) {
        $.each(receiverUserIds.to, function (i, v) {
            // console.log(receiverUserIds.request + " " + v);
            $.ajax({
                url: '<?php echo $config["base_url"]; ?>/main/saverequestinfo/?signed_request=<?php echo $_REQUEST["signed_request"]; ?>',
                data: {
                    request_id: receiverUserIds.request,
                    receiver_id: v
                },
                type: 'POST',
                success: function (d) {
                    console.log(receiverUserIds.request + " " + v);
                }
            });
        });
    }
    //http://developers.facebook.com/docs/reference/dialogs/requests/
);

这是ajax调用的代码

function saverequestinfo() {
     $data = array(
    'inv_user_id' => 1,
    'inv_request_id' => $_POST['request_id'],
    'inv_user_fbid' => $this->fb->getUser(),
    'inv_receiver_fbid' => $_POST['receiver_id'],
    'inv_liked' => fb_isLiked($this->fb)
);

$this->main->insertrequest('invitedfriends', $data);

}

这是我的模型:

function insertrequest($tbl_name, $data) {
    $date = date('Y-m-d H:i:s');
    $qry = "INSERT INTO `".$tbl_name."` (";
    $c = count($data);
    $cc = 0;
    $f = "";
    $fv = "";
    foreach($data as $i=>$v) {
        $f .= $i;
        $fv .= "'".$v."'";
        if($cc<$c-1) {
            $f .= ",";
            $fv .= ",";
        }
        $cc++;
    }
    $qry .= $f.") VALUES(".$fv.")";

    if ($this->conn->query($qry) !== TRUE) {
        echo $this->conn->error;
        die();
    }
    $this->conn->query($qry);
}
4

0 回答 0