-3

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 />";
}
      ?>
eriq
  • 3
  • 1
  • 5
  • so many questions are there.... it's a duplicate one! – Naincy Sep 25 '14 at 14:41
  • Its not exactly a duplicate question.I have researched it and have not found an answer to the warning – eriq Sep 25 '14 at 14:43
  • Why is your first move to ask the question here instead of going to php.net/mysql_query and check what the hell argument order should be? Is it really that difficult? It even tells you nicely what the problem is. – N.B. Sep 25 '14 at 14:43
  • If the code was working, you wouldn't be getting that error message. Why are you doing `$result = mysql_query($query); mysql_query($result);`? That is wrong on so many levels, and the EXACT cause of your error. – Marc B Sep 25 '14 at 14:43
  • You should always use mysqli_ functions, because mysql_ functions are out of date. – YvesHendseth Sep 25 '14 at 14:43
  • `$result=mysql_query($query);mysql_query($result);` - what is that even supposed to do? Senseless code completely. – N.B. Sep 25 '14 at 14:44

1 Answers1

0

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.

Klaus Byskov Pedersen
  • 117,245
  • 29
  • 183
  • 222