Friend List Problem (SOLVED... By myself :p )

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
62896dude
Posts: 516
Joined: Thu Jan 20, 2011 2:39 am

Friend List Problem (SOLVED... By myself :p )

Post by 62896dude »

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:

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>";
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:

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
}
?>
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:

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>";
}
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:

Code: Select all

elseif( mysql_num_rows( mysql_query( $ck_self ) ) !== 0 )
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!
Last edited by 62896dude on Wed Jun 22, 2011 7:22 am, edited 1 time in total.
Languages: C++, C#, Javascript + Angular, PHP
Programs: Webstorm 2017, Notepad++, Photoshop
Current Project: HP Destiny
User avatar
62896dude
Posts: 516
Joined: Thu Jan 20, 2011 2:39 am

Re: Friend List Problem

Post by 62896dude »

Hehe, nevermind my question, I was just about to fall asleep when I figured out the solution! I had been completely over-complicating it, all I need to say for elseif statement is:

Code: Select all

elseif ($player = $newfriend){
blah blah blah
}
Im not on my compiter to test this code, but I am pretty much sure that it will work! Hooray for right-before-bed-epiphanies! :D
Languages: C++, C#, Javascript + Angular, PHP
Programs: Webstorm 2017, Notepad++, Photoshop
Current Project: HP Destiny
Post Reply

Return to “Advanced Help and Support”