PHP and MySQL question

Discuss Programming
Post Reply
byrdman
administrator
administrator
Posts: 225
Joined: Thu May 08, 2003 1:59 pm
Location: In the cloud

PHP and MySQL question

Post by byrdman » Wed Oct 07, 2009 10:22 am

I have a php page that generates XML output. The beginning of the php has this:

Code: Select all

$zip = mysql_real_escape_string($_GET['zip']);

$query="SELECT * FROM int_weather AS w, int_forecast AS f WHERE w.zip = f.zip AND f.zip = $zip";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

so when I type in my browser http://my.domain.com/intweather.php?zip=99999
the above will return the correct row.

But I am trying to pull internation weather so I am using EGLL (Heathrow Airport, London) and my gather weather is inserting EGLL as the zip. MySQL field for zip is 'varchar'
when I do http://mydomain.com/intweather.php?zip=EGLL
I get :
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /var/www/html/rss/intweather.php on line 10.

Line 10 is $num=mysql_numrows($result);

is there something with the mysql_real_escape_string can only be a number?
If I do zip=458974594378 or some number I know is not in the db, it returns a blank page. if I do any sort of letter I get the Error message above.

Any ideas?

byrdman
administrator
administrator
Posts: 225
Joined: Thu May 08, 2003 1:59 pm
Location: In the cloud

Post by byrdman » Wed Oct 07, 2009 10:23 am

Another thing, I go into mysql and do the query:

SELECT * FROM int_weather AS w, int_forecast AS f WHERE w.zip = f.zip AND f.zip = 'EGLL"
it returns the correct data, but when I put it into the URL query is when I get the error.

Just wanted to clarify.

byrdman
administrator
administrator
Posts: 225
Joined: Thu May 08, 2003 1:59 pm
Location: In the cloud

Post by byrdman » Wed Oct 07, 2009 12:32 pm

Found my own answer by trial and error.

added single quotes around the $zip at the end so my second line of code looks like:

Code: Select all

$query="SELECT * FROM int_weather AS w, int_forecast AS f WHERE w.zip = f.zip AND f.zip = '$zip'";

Post Reply