Jump to content

[SOLVED] Check if record exists


scottjcampbell

Recommended Posts

Hi, i have been trying this for some time now, i will try my best to explain, but i am not very good at it.

 

I have a friends system on my website, that works fine, once a user accepts a friend request, their name, and the person who wants to be friends with the are put into a table like this:

tables.jpg

 

I am now trying (And Failing) to make a script which will display a certain message if the user is friends with the person who's profile they are viewing, here is my code so far:

$username = $_SESSION['username'];
$q = "SELECT username,friendname FROM friends WHERE `username` = $requser";
$result = $database->query($q);

/* Display table contents */
for($i=0; $i<$num_rows; $i++){
$fname  = mysql_result($result,$i,"friendname");
}
if ($fname==$requser){
echo "YES!";
}else{
echo "NO!";
}

But i am always getting "YES!" even if they are not friends.

 

Variables:

  • $requser is defined in the title of the profile (e.g domain.com/profile.php?user=test)
  • $username is the person who is viewing the profile

So i wanted to make it that if $username (Viewer) is friends with $requser (Person who's profile they are viewing) then thry will see"Yes!", otherwise, they will see "No!"

 

P.S DATABASE CREDENTIALS ARE DEFINED ABOVE IN THE CODE

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.