Possible Duplicate:
PHP: Warning: sort() expects parameter 1 to be array, resource given
here is my code: I see nothing that should be causing this...ideas?
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given.
<?php
include_once "mysql_connect.php";
if ($_POST['parse_var'] == "contactform"){
if(is_array($categories)) $whereCond = "in '".implode(",",$categories); else
$wherecond = "= ".$categories;
$dropdownValue = $_POST['dropdown'];
$dropdownValue = mysql_real_escape_string($dropdownValue);
$dropdownValue = eregi_replace("`", "", $dropdownValue);
$searchField= $_POST['searchinput'];
$searchField = mysql_real_escape_string($searchField);
$searchField = eregi_replace("`", "", $searchField);
if ($dropdownValue == "phone"){
$sql = mysql_query("SELECT * FROM pcparts WHERE phone='$searchField'");
while($row1 = mysql_fetch_array($sql)){
$arrayuserinfo[] = array(
'phone' => $row1["phone"],
'name' => $row1["name"],
'city' => $row1["city"],
'state' => $row1["state"],
'address' => $row1["address"],
'zip' => $row1["zip"],
);
};
for($i=0;$i < count($arrayuserinfo);$i++){
$phone = $arrayuserinfo[$i]["phone"];
$name = $arrayuserinfo[$i]["name"];
$city = $arrayuserinfo[$i]["city"];
$state = $arrayuserinfo[$i]["state"];
$address = $arrayuserinfo[$i]["address"];
$zip = $arrayuserinfo[$i]["zip"];
echo"<table width='400' border='1' cellpadding='3'>
<tr>
<td>phone</td>
<td>name</td>
<td>address</td>
<td>city</td>
<td>state</td>
<td>zip</td>
</tr>
<tr>
<td>$phone</td>
<td>$name</td>
<td>$address</td>
<td>$city</td>
<td>$state</td>
<td>$zip</td>
</tr>
</table><br />
";
}
}
else if ($dropdownValue == "name"){
$sql = mysql_query("SELECT * FROM pcparts WHERE name='$searchField'");
while($row1 = mysql_fetch_array($sql)){
$arrayuserinfo[] = array(
'phone' => $row1["phone"],
'name' => $row1["name"],
'city' => $row1["city"],
'state' => $row1["state"],
'address' => $row1["address"],
'zip' => $row1["zip"],
);
};
for($i=0;$i < count($arrayuserinfo);$i++){
$phone = $arrayuserinfo[$i]["phone"];
$name = $arrayuserinfo[$i]["name"];
$city = $arrayuserinfo[$i]["city"];
$state = $arrayuserinfo[$i]["state"];
$address = $arrayuserinfo[$i]["address"];
$zip = $arrayuserinfo[$i]["zip"];
echo"<table width='400' border='1' cellpadding='3'>
<tr>
<td>phone</td>
<td>name</td>
<td>address</td>
<td>city</td>
<td>state</td>
<td>zip</td>
</tr>
<tr>
<td>$phone</td>
<td>$name</td>
<td>$address</td>
<td>$city</td>
<td>$state</td>
<td>$zip</td>
</tr>
</table><br />
";
}
}
else if ($dropdownValue == "city"){
$sql = mysql_query("SELECT * FROM pcparts WHERE city='$searchField'");
while($row1 = mysql_fetch_array($sql)){
$arrayuserinfo[] = array(
'phone' => $row1["phone"],
'name' => $row1["name"],
'city' => $row1["city"],
'state' => $row1["state"],
'address' => $row1["address"],
'zip' => $row1["zip"],
);
};
for($i=0;$i < count($arrayuserinfo);$i++){
$phone = $arrayuserinfo[$i]["phone"];
$name = $arrayuserinfo[$i]["name"];
$city = $arrayuserinfo[$i]["city"];
$state = $arrayuserinfo[$i]["state"];
$address = $arrayuserinfo[$i]["address"];
$zip = $arrayuserinfo[$i]["zip"];
echo"<table width='400' border='1' cellpadding='3'>
<tr>
<td>phone</td>
<td>name</td>
<td>address</td>
<td>city</td>
<td>state</td>
<td>zip</td>
</tr>
<tr>
<td>$phone</td>
<td>$name</td>
<td>$address</td>
<td>$city</td>
<td>$state</td>
<td>$zip</td>
</tr>
</table><br />
";
}
}
}
?>
<html>
<body>
<h2>Customers Database Search</h2>
<form action="file1.php" method="POST">
<input type='hidden' name='parse_var' value='contactform'>
Search fields:
<select name="dropdown" id="dropdown" >
<option value="<?php print "$dropdownValue"; ?>"><?php print "$dropdownValue"; ?></option>
<option value="phone">phone</option>
<option value="name">name</option>
<option value="city">city</option>
</select>
Search item:<input type="text" name='searchinput' id="searchinput" value="
<?php print "$searchField"; ?>" size='20'><br><br>
<input type="submit" name="button" id="button" value="Search" />
</form>
<br />
<br />
</body>
</html>
mysql_connect:
<?php
$db_host = "localhost";
$db_username = "user";
$db_pass = "test1234";
$db_name = "pcparts";
@mysql_connect("$db_host","$db_username","$db_pass") or die ("Could not connect to MySQL");
@mysql_select_db("$db_name") or die ("No database");
?>
if you find something i need to add, can you please tell me exactly where to put it?