Friend List Problem (SOLVED... By myself :p )
Posted: Wed Jun 22, 2011 6:30 am
Hello,
It is currently 1:23 a.m. where I am at. I think I need to just step away from my code after a long day and stop trying to figure this out, cuz its killing me :p
So anyways, here is my add_friend.php:
That code is just the form that you use to type in the username of the friend you want to add.
Here is the friendck.php:
That is the script that actually adds the friend. Now here is my problem:
Every aspect of the script works marvelously except for one part. In friendck.php where it says:
This is where I am getting issues. No matter who I add as a friend through my form created in add_friend.php, it echoes "You can't add yourself! Go back and add someone else!". Now this is helpful because it tells me that the problem is associated with this part of the script:
Do you guys have any idea what is going wrong here that is causing this to happen? Again, I can't think straight right now, and would really appreciate someone else's input who hasn't been staring at this single line of code for 20 minutes 
Thanks everyone!
It is currently 1:23 a.m. where I am at. I think I need to just step away from my code after a long day and stop trying to figure this out, cuz its killing me :p
So anyways, here is my add_friend.php:
Code: Select all
<html>
<head>
</head>
<body>
<?php
include_once 'connect.php';
session_start();
include_once 'logo.php';
?>
<link href="style.css" rel="stylesheet" type="text/css" />
<div id="login2" div align="center">
<?php
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
}
else
{
echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
exit;
}
?>
</div>
<?php
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
include_once 'statpanel.php';
$bypass = 0
?>
<form name="message" action="friendck.php"
method="post">
Add Friend: <input type="text" name="add"><br>
</body>
</html>
<?php
echo "<br><br><br><a href='index.php'>Go Back</a>";
Here is the friendck.php:
Code: Select all
<?php
include_once 'connect.php';
session_start();
include_once 'logo.php';
?>
<link href="style.css" rel="stylesheet" type="text/css" />
<div id="login2" div align="center">
<?php
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
}
else
{
echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
exit;
}
?>
</div>
<?php
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
include_once 'statpanel.php';
$bypass = 0
?>
<?php
$newfriend=$_POST['add'];
$uid=$playerinfo3['id'];
$fid=$newfriend['id'];
$uname=$playerinfo3['name'];
$ck_self = "SELECT name FROM players WHERE name = '".$player."'";
$ck_friendlist = "SELECT friend_name FROM friends WHERE friend_name = '".$newfriend."'";
$ck_friend = "SELECT name FROM players WHERE name = '".$newfriend."'";
if( mysql_num_rows( mysql_query( $ck_friend ) ) == 0 ){
die("The user you are trying to add doesn't exist. Please go back and try again.<br>
<form name=\"back\" action=\"add_friend.php\"
method=\"post\">
<input type=\"submit\" value=\"Try Again\">
</form>
");
}
elseif( mysql_num_rows( mysql_query( $ck_friendlist ) ) !== 0 ){
echo "You already are friends with this user, go back and add another person!<br><br>";
echo "<a href='add_friend.php'>Go Back</a>";
}
elseif( mysql_num_rows( mysql_query( $ck_self ) ) !== 0 ){
echo "You can't add yourself! Go back and add someone else!<br><br>";
echo "<a href='add_friend.php'>Go Back</a>";
}
else{
mysql_query("INSERT INTO friends (user_id, friend_id, user_name, friend_name) VALUES ('$uid','$fid','$uname','$newfriend')") OR die("Could not send the message: <br>".mysql_error());
echo "Friend was successfully added!";
?>
<form name="back" action="add_friend.php"
method="post">
<input type="submit" value="Add another friend">
</form>
<?php
}
?>
Every aspect of the script works marvelously except for one part. In friendck.php where it says:
Code: Select all
elseif( mysql_num_rows( mysql_query( $ck_self ) ) !== 0 ){
echo "You can't add yourself! Go back and add someone else!<br><br>";
echo "<a href='add_friend.php'>Go Back</a>";
}
Code: Select all
elseif( mysql_num_rows( mysql_query( $ck_self ) ) !== 0 )

Thanks everyone!