hi,
I'mm writing script for adding friend to a friend list.i'm using a form including friend_name (text), message (textarea) and below is my code:
[php]
if(isset($_POST['send']))
{
include('dbconnect.php');
$friend=$_POST['friend2'];
$user=$_COOKIE['username'];
$result=mysql_query("SELECT * FROM friendlist WHERE username='$user'");
$rows=mysql_fetch_array($result);
echo $friend;
$added_friend=$rows['friend'];
echo $added_friend;
$user1=$rows['username'];
echo $user1;
if(($friend==$added_friend)&&($user==$user1))
{
?><script>alert('<? echo $friend; ?> has been on your list already!');
window.location="friendpublic.php";
</script><?
}
else
{
$query="INSERT INTO friendlist (username,friend) VALUES ('$user','$friend')";
mysql_query($query) or die(mysql_error);
?><script>alert('<? echo $friend; ?> has been added to your list!')</script><?
$invite=$_POST['invite'];
$query2="INSERT INTO friend_message (sender,receiver,message,status)
VALUES ('$user','$friend','$invite','1')";
mysql_query($query2) or die(mysql_error);
?><script>alert('A message has been sent to him or her!');
window.location="friendpublic.php";
</script><?
}
}
?>
[/php]
the code [php]if(($friend==$added_friend)&&($user==$user1))[/php] is used to check if the friend was already on the list but somehow it doesn't work. i think the problem is the mysql_fetch_assoc which queries the first row on the friendlist table...
can anyone show me how to fix it?
thanks!