This question already has an answer here:
Warning: mysql_query() expects parameter 1 to be string, resource given in C:\wamp\www\life\homeSearch.php on line 20
The code is working but displaying the above error. Here is the code:
<?php
ob_start();
require("config.php");
ob_end_clean();
$req=$_REQUEST['propertyType'];
$req2=$_REQUEST['propertyStatus'];
mysql_connect("localhost",$username,$password);
mysql_select_db("$database") or die( "Unable to select database");
if ($req!="all" && $req2!="all") $query= "SELECT * FROM buildings WHERE propertyType='$req' AND propertyStatus='$req2'";
else if($req=="all" && $req2!="all" ) $query= "SELECT * FROM buildings WHERE propertyStatus='$req2'";
else if($req!="all" && $req2=="all" ) $query= "SELECT * FROM buildings WHERE propertyType='$req'";
else if($req=="all" || $req2=="all" ) $query= "SELECT * FROM buildings";
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_query($result);
mysql_close();
$i=0;
for ($i; $i < $num; $i++){
$f12=mysql_result($result,$i,"availability");
$f13=mysql_result($result,$i,"propertyType");
$f14=mysql_result($result,$i,"propertyStatus");
echo $f12." ".$f13." <br /> ".$f14."<br />";
}
?>
</div>
You need to remove the following line from your code to make the warning go away:
mysql_query($result);
You aready assigned $result
to the result of your query a few lines up:
$result=mysql_query($query);
So it is now telling you that mysql_query($result);
is not valid because it expects a string, and you are effectively passing the result of a query to it.