Jump to content

Recommended Posts

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'];

?>

 

Link to comment
https://forums.phpfreaks.com/topic/174014-solved-weird-insert-error/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.