Database accessing error, some php function maybe
<p>I was working on a script but got stuck at a point.</p>

<p>But under the file where it gets user id from the user and set a verification code and store in the database to notify the other user when it is being accessed. The code is about adding a friend, verifying it and deleting the friend from then list. The error is that when somebody request the friend to be added, no notification is received and moreover the other party can still add the first party as a friend but no effect is received on the either side. I think I am not able to get what the actual problem is....I have checked the calling and accessing function but not able to find out whats getting me problem here. the field values in the database are as follows - id/friend_id/user_id/verify_code</p>

<p>This is the code -</p>

<pre><code>@session_start();
if(empty($_SESSION["email"]) and empty($_SESSION["display_name"]) )
{
header("Location: ./login.php");
exit;
}

$user_id=get_user_data('user_id');

$id=$_GET[id];
//////////////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////////////
if($_GET[f]=='verifyfriend' &amp;&amp; $_GET[code]!='')
{ 
//confirm
$result=mysql_query("SELECT * FROM `friend` where `verify_code`='$_GET[code]' ");
if(mysql_num_rows($result)) // existing verify code.
{
//clear code
$row=mysql_fetch_assoc($result);
mysql_query("UPDATE `friend` SET `verify_code`='' WHERE                             `verify_code`               '$_GET[code]'");

    //add friend's friend
    mysql_query("INSERT INTO `friend` (`friend_id` ,`user_id` ) VALUES ('$row[user_id]', '$row[friend_id]') ");


    //update friend number: initiator
    $row2 = mysql_fetch_array(mysql_query("select * from `user` where user_id='$row[user_id]'"));
    $friends_num=$row2[friends_num]+1;
    $query="UPDATE `user` set friends_num='$friends_num' where user_id='$row[user_id]'";
    $result=mysql_query($query);
    //update friend number: friend
    $row3 = mysql_fetch_array(mysql_query("select * from `user` where user_id='$row[friend_id]'"));
    $friends_num=$row3[friends_num]+1;
    $query="UPDATE `user` set friends_num='$friends_num' where user_id='$row[friend_id]'";
    $result=mysql_query($query);


}



echo "&lt;script&gt;alert('".l('Friend added!')."'); location='/my/'&lt;/script&gt;";




}


//////////////////////////////////////////////////////////////////////////
if($_GET[f]=='addfriend')
{
// 就是否已经是好友
$result=mysql_query("SELECT * FROM `friend` where user_id='$user_id' and friend_id='$id' and `verify_code`='' ");

if(mysql_num_rows($result)==0&amp;&amp;$user_id!=$id)
{
    $query="DELETE FROM `friend` where `user_id`='$user_id' and `friend_id`='$id' ";
    $result=mysql_query($query);

    $code=md5(rand());
    $query="insert into `friend` (`user_id`,`friend_id`, `verify_code`) values ('$user_id','$id', '".$code."')";
    $result=mysql_query($query);

    $url="http://"._DOMAIN_."/my/func.php?f=verifyfriend&amp;code=".$code;
    mailcom($id,'addfriend',"$url");

    //////////end friend number////////
    echo "{'MSG':'1'}";
}
else
{
    echo "{'MSG':'0'}";
}
exit;
}
//////////////////////////////////////////////////////////////////////////
if($_GET[f]=='delfriend')
{
$result=mysql_query("delete from `friend` where user_id='$user_id' and friend_id='$id' limit 1");   
////////user 's  friend number //////////
    $row = mysql_fetch_array(mysql_query("select * from `user` where user_id='$user_id'"));
    $friends_num=$row[friends_num]-1;
    $query="UPDATE `user` set friends_num='$friends_num' where user_id='$user_id'";
    $result=mysql_query($query);
//////////end friend number////////
echo "&lt;script&gt;alert('".l('Friend deleted!')."');&lt;/script&gt;"  ;

}
</code></pre>
