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!

Query limits?

Status
Not open for further replies.

edpatterson

IS-IT--Management
Feb 24, 2005
186
I am at a loss, the query works fine using source query.sql but when I put the query into a php page it bombs.

Code:
	$query = "SELECT addresses.address as 'address',"
                    ." equipment.serial as 'serial',"
                    ." status.name as 'status',"
                    ." types.name as 'type',"
                    ." sites.name as 'site',"
                    ." rooms.name as 'room'"
                    ." FROM addresses, equipment, status, types, sites, rooms"
                    ." WHERE equipment.serial like 4KL1271"
                    ." AND equipment.equipID = addresses.equipID"
                    ." AND equipment.statusID = status.statusID"
                    ." AND equipment.typeID = types.typeID"
                    ." AND equipment.roomID = rooms.roomID"
                    ." AND addresses.siteID = sites.siteID";
	$result = mysql_query($query);
	while($field = mysql_fetch_field($result)){
          <other stuff here>
        }
I get the following error
[tt]
Warning: mysql_fetch_field(): supplied argument is not a valid MySQL result resource in e:\ipdatabase\iputility.php on line 27
[/tt]

In actual use the serial number would be $_POST['serial']

Ed
 
As a basic first step, I recommend changing this line:

$result = mysql_query($query);

to read:

$result = mysql_query($query) or die (mysql_error());


That way, you can get your script to tell you what MySQL doesn't like about your query.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
and then changing
." WHERE equipment.serial like 4KL1271"
to
." WHERE equipment.serial like '".$_POST['serial']."'"

or for testing
." WHERE equipment.serial like '4KL1271'"

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
You folks are rocker scientists!

I had no idea that there was a die function in PHP.

The ' around the serial was the problem.

Thanks a million!

Ed
 
rocker = rocket

The spell checker did not complain :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top