Hi all, im sure this will be areally quick solution for you masters out there,

Im trying to create a SELECT query but I am continually getting a parse error ?

$query="SELECT * FROM friends WHERE (user_id = '$_SESSION[SESS_MEMBER_ID]' AND request_id = '$profile_id') OR (request_id = '$_SESSION[SESS_MEMBER_ID]' AND user_id = '$profile_id')";
$result = mysql_query($query);
$row = mysql_num_rows($result);

Hope someone can point me in the right direction as to where I am going wrong

Recommended Answers

All 5 Replies

try putting single quotes (') around both SESS_MEMBER_ID instances in the query.

@rozendaa hi, thanks for your input,

When I use single quotes i get the following error message

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\xampp\htdocs\www.website.com\members\addfriends.php on line 33

is it best to use INSERT INTO friends

or UPDATE friends SET

Sorry, to short an answer. The additional quotes were intended for php to proces. And for that to work you must use explicit concatenation.
The following should work.

$query="SELECT * FROM friends WHERE (user_id = '".$_SESSION['SESS_MEMBER_ID']."' AND request_id = '$profile_id') OR (request_id = '".$_SESSION['SESS_MEMBER_ID']."' AND user_id = '$profile_id')";
$result = mysql_query($query);
$row = mysql_num_rows($result);
Member Avatar for rajarajan2017

Also give a try for this:

$query="SELECT * FROM friends WHERE (user_id = $_SESSION['SESS_MEMBER_ID'] AND request_id = $profile_id) OR (request_id = $_SESSION['SESS_MEMBER_ID'] AND user_id = $profile_id)";
Member Avatar for diafol

When using array vars inside double quotes - brace {} them out:

$query="SELECT * FROM friends WHERE (user_id = '{$_SESSION['SESS_MEMBER_ID']}' AND request_id = '$profile_id') OR (request_id = '{$_SESSION['SESS_MEMBER_ID']}' AND user_id = '$profile_id')";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.