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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable puzzler

Status
Not open for further replies.

VirtualOdin

Technical User
Sep 7, 2003
2
GB
I am a relative novice to PHP/MySQL, but this one really has me stumped.

The following statements work fine and return all the records from books where sector is IT.

$query = "select * from books where sector = 'IT' ";
$result = mysql_query( $query );
$numresults = mysql_num_rows( $result );

And these generate "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource"

$sector = "IT";
$query = "select * from books where sector = $sector ";
$result = mysql_query( $query );
$numresults = mysql_num_rows( $result );

Any ideas on what could be going wrong?

I'd appreciate any ideas. I have tried what seems to be everything!

Tim
 
Code:
$query = "select * from books where sector = $sector ";
should be
Code:
$query = "select * from books where sector = '$sector' ";

//Daniel
 
I thought I had tried every possible permutation of quotes, fullstops, etc, but evidently not this one. Many thanks Daniel. Now fixed. I wish I had asked earlier...

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top