Jump to content

[How to] Checking to see if two variables are in a row.


gtrufitt

Recommended Posts

Hi,

 

I am trying to build a friends list. I have the tables:

 

user with the columns: userid, f_name.

friends with the columns: id, friendid.

 

So far I am using the query:

 

$friendid = $_GET['friendid'];

$getfriend = "SELECT id, friendid FROM friends WHERE friendid = '$friendid'";

$fr = mysql_query($getfriend) or die(mysql_error()."<Br /><br /.".$login); // don't use your SQL statement in your error. It will let malicious users know your table structure and open it up to sql injection.

$countfr = mysql_num_rows($fr);

$row = mysql_fetch_array($fr);
$id = $sesid;
$friendid = $row['friendid'];

 

Where $friendid is using GET to pass the variable from a previous page.

and $sesid is saved as the logged in user's ID as a session variable.

 

How do I check to see if the users are already friends, by checking to see if both $friendid and $id are in a row?

 

Thanks

Link to comment
Share on other sites

use the sql logical 'AND' operator

$getfriend = "SELECT id, friendid FROM friends WHERE id = '$sesid' AND friendid = '$friendid'";

--one note: if id and friendid are defined as numeric type fields in your db, like integers, leave off the single quotes around the use of them in your sql statement.

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.