我正在制作一个剧本但却陷入困境。
但是在该文件中,它从用户获取用户ID并设置验证码并存储在数据库中以通知其他用户何时被访问。代码是关于添加朋友,验证它并从列表中删除朋友。错误是当有人请求添加朋友时,没有收到通知,而且另一方仍然可以将第一方添加为朋友,但是在任何一方都没有收到任何效果。我想我无法得到实际问题是什么....我已经检查了调用和访问功能,但无法找到最新问题。数据库中的字段值如下 - id / friend_id / user_id / verify_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' && $_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 "<script>alert('".l('Friend added!')."'); location='/my/'</script>";
}
//////////////////////////////////////////////////////////////////////////
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&&$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&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 "<script>alert('".l('Friend deleted!')."');</script>" ;
}
答案 0 :(得分:0)
@session_start();
if(empty($_SESSION["email"]) && empty($_SESSION["display_name"]) )
{
header("Location: ./login.php");
exit;
}
$user_id=get_user_data('user_id');
$id=$_GET['id'];
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
if($_GET['f']=='verifyfriend' && $_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]++;
$query="UPDATE user set friends_num='$friends_num' where user_id='$row[friend_id]'";
$result=mysql_query($query);
}
echo "<script>alert('".l('Friend added!')."'); location='/my/'</script>";
}
//////////////////////////////////////////////////////////////////////////
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 && $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&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 "<script>alert('".l('Friend deleted!')."');</script>" ;
}