Jump to content

[SOLVED] Weird insert error


randall

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.