使用php mysql ajax jquery为朋友系统创建一个接受或拒绝操作

时间:2013-05-16 18:40:44

标签: php mysql jquery

我有一个朋友请求系统,允许用户向其他人发送请求,我有一个接受或拒绝按钮。但问题是代码中有些东西不能写入并使系统无法显示,我不知道错误在哪里 任何人都可以帮助我?????

这是ajax部分

//function for accepting freinds
function acceptFriendRequest(x){    
$.post(url,{request:"acceptFriend",reqID:x,thiswipt:thisRandNum},function{data}{
    $("#req"+x).html(data).show();
    ));
}

//function to deny friend request
function denyFriendRequest(x){
$.post(url,{request:"denyFriend",reqID:x,thiswipt:thisRandNum},function{data}{
    $("#req"+x).html(data).show();
    ));
}

php代码:

///***************IF ACCEPT FRIEND***************//
if($_POST["request"]=="acceptFriend")
{
   $reqID = preg_replace('#[^0-9]#i', '', $_POST['reqID']);
   $sql = mysql_query("SELECT * FROM friend_requests WHERE id = '$reqID' LIMIT 1")or die(mysql_error());
   $numRow = mysql_num_rows($sql);
   if($numRow<1)
   {
       echo "An error occured";
       exit();
   }
   while($row = mysql_fetch_array($sql))
   {
       $mem1 = $row['mem1'];
       $mem2 = $row['mem2'];


   }


  //query for mem1 mem2 array
   $sql_frnd_mem1_array = mysql_query("SELECT friend_array FROM members WHERE  user_id='$mem1' LIMIT 1")or die(mysql_error());
   $sql_frnd_mem2_array = mysql_query("SELECT friend_array FROM members WHERE  user_id='$mem2' LIMIT 1")or die(mysql_error());
   while($row = mysql_fetch_array($sql_frnd_mem1_array))
   {
       $frnd_array_mem1 = $row['friend_array'];
   }
   while($row = mysql_fetch_array($sql_frnd_mem2_array))
   {
       $frnd_array_mem2 = $row['friend_array'];
   }
   $frnArrayMem1 = explode(",",$frnd_array_mem1);
   $frnArrayMem2 = explode(",", $frnd_array_mem2);

   //*******************PREVENT DUPLICATION IN id**************
   if(in_array($mem2,$frnArrayMem1))
   {
       echo "this member is already your friend!";
       exit();
   }
   if(in_array($mem1,$frnArrayMem2))
   {
       echo "this member is already your friend!";
       exit();
   }

   // puting each other in friend array field
   if($frnd_array_mem1 !="" )
   {
       $frnd_array_mem1 ="$frnd_array_mem1, $mem2";
   }
   else
   {
       $frnd_array_mem1 = "$mem2";
   }
   if($frnd_array_mem2 !="" )
   {
       $frnd_array_mem2 ="$frnd_array_mem2, $mem1";
   }
   else
   {
       $frnd_array_mem2 = "$mem1";
   }
   $UpdateArrayMme1 = mysql_query("UPDATE  members SET friend_array = '$frnd_array_mem1' WHERE user_id = '$mem1'") or die(mysql_error());
    $UpdateArrayMme2 = mysql_query("UPDATE  members SET friend_array = '$frnd_array_mem2' WHERE user_id = '$mem2'") or die(mysql_error());
    $deleteThisPendingRequest =mysql_query("DELETE FROM friend_requests WHERE id = '$reqID' LIMIT 1")or die(mysql_error());  
    echo "you are now friend with this member!";
    exit();
}
//*********deny Friend***************
if($_POST['request']=="denyFriend")
{
    $reqID = preg_replace('#[^0-9]#i', '', $_POST['reqID']);
    $deletethisPendigRequest = mysql_query("DELETE FROM friend_requests WHERE user_id = '$reqID' LIMIT 1 ")or die(mysql_error());
    echo "Request Denied";
    exit();
}

1 个答案:

答案 0 :(得分:1)

我认为你的代码有问题:

    //function for accepting freinds
    function acceptFriendRequest(x){    
    $.post(url,{request:"acceptFriend",reqID:x,thiswipt:thisRandNum},function{data}{
        $("#req"+x).html(data).show();
        ));     
    }

    //function to deny friend request
    function denyFriendRequest(x){
    $.post(url,{request:"denyFriend",reqID:x,thiswipt:thisRandNum},function{data}{
        $("#req"+x).html(data).show();
        ));
    }

function{data}{}应为function(data){}