randall Posted September 12, 2009 Share Posted September 12, 2009 When I submit a form from a previous page using a numerical zip code such as 90210 I do not get any errors. When I submit a postal code with letters such as V78445 I get the following error. Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\sites\realestate\Agent_Selector.php on line 10 Here is my code... Any help would be great! Thanks! <?php $zipcode = $_GET['zipcode']; // Connects to your Database mysql_connect("xampp", "username", "password") or die(mysql_error()); mysql_select_db("getreal") or die(mysql_error()); mysql_query("INSERT INTO popularzip (zipcode) VALUES('$zipcode')"); $details = "SELECT * FROM census WHERE ZipCode=($zipcode)"; $SQ_query = mysql_query($details); $detail = mysql_fetch_array($SQ_query); $city = $detail['City']; $state = $detail['StateFullName']; $areacode = $detail['AreaCode']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/174014-solved-weird-insert-error/ Share on other sites More sharing options...
kickstart Posted September 12, 2009 Share Posted September 12, 2009 Hi Missing quotes I suspect:- $details = "SELECT * FROM census WHERE ZipCode='$zipcode'"; All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/174014-solved-weird-insert-error/#findComment-917296 Share on other sites More sharing options...
.josh Posted September 12, 2009 Share Posted September 12, 2009 in your select query you do not have $zipcode wrapped in quotes, so it is treating the value as a number (int). Your numerical zipcodes will work for that, but when you try to add letters into a mix, it is no longer a number, but a string. But the query casts it as an int value, and that value is not found in your table, so the query returns false (boolean), since it found nothing. This causes your fetch_array to fail, since it expects a result source, not a boolean. edit: keith beat me to the draw. Quote Link to comment https://forums.phpfreaks.com/topic/174014-solved-weird-insert-error/#findComment-917297 Share on other sites More sharing options...
randall Posted September 12, 2009 Author Share Posted September 12, 2009 Thank you... that solved it! Quote Link to comment https://forums.phpfreaks.com/topic/174014-solved-weird-insert-error/#findComment-917319 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.