Perpetual error with MYSQL_FETCH_ARRAY; expects resource etc
Posted: Tue Oct 25, 2011 3:29 am
Hello
This is the error:
And this is the relative code:
Entire code;
welcome.php:
search.php:
I'm ripping my hair out trying to solve this. Any ideas? Thanks
This is the error:
Code: Select all
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\search.php on line 24Code: Select all
$zip=$_POST['zip']; //form text set to variable
$sql = "SELECT * FROM zip_codes WHERE zip_code='$zip'";
$result = mysql_query($sql);
if ($row = mysql_fetch_array($result)) {
echo $row['zip_code'] . " " . $row['city'];
echo "<br />";
}Entire code;
welcome.php:
Code: Select all
<html>
<body>
<center>
<b>Zip code search!</b>
<form action="search.php" method="post">
<input type="text" name="zip"/><br>
<input type="submit" value="SEARCH"/>
</form>
</center>
</body>
</html>
search.php:
Code: Select all
<?php
$db_host = 'x';
$db_user = 'x';
$db_pass = 'x';
$db_name = 'x';
//set search text as variable
$zip=$_POST['zip'];
//echo text
echo $zip;
//kill script if null
if ($zip==NULL) {
die ("null" . mysql_error());
}
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
$sql = "SELECT * FROM zip_codes WHERE zip_code='$zip'";
$result = mysql_query($sql);
if ($row = mysql_fetch_array($result)) {
echo $row['zip_code'] . " " . $row['city'];
echo "<br />";
}
?>
I'm ripping my hair out trying to solve this. Any ideas? Thanks