Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

doing a mysql query with AND connector

Status
Not open for further replies.

yahoo182

Programmer
Jul 5, 2005
70
CA
Hi there, I have a single line of sql statement and it works just fine
Code:
$fetchid = @mysql_query("select * from tomapping where TOID='$toid'");

However, when I try to use the AND clause to narrow down my search result, I get an error saying that there is something wrong near " but I do not see what is worng with the statement.

Code:
$fetchid = @mysql_query("select * from tomapping where TOID='$toid' AND HotelName='$hotelname' ");
 
Just for fun, try this:
Code:
$fetchid = @mysql_query("select * from tomapping where TOID='$toid' AND HotelName='".$hotelname."' ");

[cheers]
Cheers!
Laura
 
Hi there,
That worked just fine! Its so strange though. Why did my previous one not work?
Is there something to do with the single, double quotes in PHP?

But thanks LTeeple.
 
Your statement looks perfectly ok as is.

It could have been that the hotelname contained a single quote: O'Leary, Smackers' Choice?

To prevent that you should escape the content of the parameters with mysql_real_escape_string().

Further: Stay away from the @ operator and add some useful error checking to the statement.
Code:
$result = mysql_query($SQL) OR die("Query error: ".$SQL." ::".mysql_error());
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top