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
https://forums.phpfreaks.com/topic/121272-solved-check-if-record-exists/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.