0

SELECT * FROM onlinepg as pg, pg_rooms as rooms WHERE pg.pg_id=rooms.pg_id and pg.status=0 AND ( rooms.roomtype='Sharing Basis' )

How I can write above query in PHP.. so that I can run successfully on mysql.

4
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by abhi10kumar
0

I Knew all above stuffs.. But when I run above sql I got error on server.. Actually it is running on local but not on server..

**SQL query failed. Check your query.

Error Returned: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'Sharing Basis\' )' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'Sharing Basis\' )' at line 1
**

0

'\'Sharing Basis\' )'

looks like a missuse of mysql_real_escape_string
can u post the php-code used to create the query?

0

if(!(empty($roomtype)))
{
foreach($roomtype as $r)
$rr.="rooms.roomtype='$r' or ";
if(strlen($rr)==0)
$rr="";
else
{
$rr = substr($rr, 0, -3);
$rr=" AND ( $rr ) ";
}
}

Edited by abhi10kumar: inaccurate

0

Error Returned: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'Sharing Basis\' )' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'Sharing Basis\' )' at line 1

when you see that it's usually something quite close just before '\'Sharing Basis\' )' such as a missing comma, or empty number variable or extra/missing brackets.

Basically mysql is evaluating your query and that is the first part that doesn't make sense based on what was said before it

get php to print out the query it is running to the page just before it runs it so you can see what it is doing eg.

$query = "blah blah";
echo $query;
mysql_query($query);
0

Echoing Sql query and running that on server does not have problem. Actaully, it is running on local but not on Server.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.