Im having problems with the code below, i got this off a book but tried modifying the code to carry out multiple search criterias, when the search is carried out i get the following error:

Catchable fatal error: Object of class stdClass could not be converted to string in C:\Program Files\xampp\htdocs\searchextended.php on line 768

this is line 768:
echo "$row-> User_Name, $row->To_Rent_Price ($row->Property_Details)<br />" ;

 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<p> <br />
<form action="searchextended.php" method="post">
<div align="left">Location: <br />
    <input type="text" name="keyword" size="20" maxlength="40" value="" />
    <br />
    <label> Property type:
      <select name="propertytype">
      <option>All Types</option>
      <option>Flat/Apartment</option>
      <option>Maisonette</option>
      <option>House</option>
    </select>
    </label>
    <br  />
    <label> Rent (monthly):
      <select name="rent_min">
      <option value="0" selected />  

       No minimum


    <option value="1"  />  
  £50 

    <option value="2"  />  
  £100 



  </select>
</label>
<select name="rent_max">
  <option value="0" selected />  


       No maximum



  <option value="1"  />  
  £50 



  <option value="2"  />  
  £100 


</select>
<br  />
<label> Bedrooms:
  <select name="bedrooms_min">
  <option value="0" selected />  



  Studio 



    <option value="1"  />  



  1 bedroom 




    <option value="2"  />  



  2 bedrooms 




    <option value="3"  />  



  3 bedrooms 




    <option value="4"  />  



  4 bedrooms 




    <option value="5"  />  



  5 bedrooms 




    <option value="6"  />  



  6 bedrooms 




    <option value="7"  />  



  7 bedrooms 




    <option value="8"  />  



  8 bedrooms 




    <option value="9"  />  



  9 bedrooms




  </select>
<select name="bedrooms_max">
  <option value="1"  />  



  1 bedroom 



  <option value="2"  />  




  2 bedrooms 



  <option value="3"  />  





  3 bedrooms 






  <option value="4"  />  





  4 bedrooms 






  <option value="5"  />  





  5 bedrooms 






  <option value="6"  />  





  6 bedrooms 






  <option value="7"  />  





  7 bedrooms 






  <option value="8"  />  





  8 bedrooms 






  <option value="9"  />  



	      9 bedrooms     





  <option value="0" selected />  



	       No maximum       

</select>
<br  />
<input type="checkbox" name="swimmingpool" value="checkbox" />
  Swimming Pool </label>
<p>
  <input type="checkbox" name="garden" value="checkbox" />
  Garden <br  />
  <input type="checkbox" name="drivebay/garage" value="checkbox" />
  Drive Bay/Garage
  <input type="checkbox" name="streetparking" value="checkbox" />
  Street Parking <br />

</p>
<p>  
  <input name="submit" type="submit" value="Search!" />
</p>
</div>
<br />
<br />
</form>
</p>


<?php

//if the form has been submitted with a supplied search criteria
if (isset($_POST['keyword']) || isset($_POST['propertytype']) || isset($_POST['rent_min']) || isset($_POST['rent_max']) || isset($_POST['bedrooms_min']) || isset($_POST['bedrooms_max'])) 
{

//connect to server and select database
$mysqldb = new mysqli("localhost", "username", "password", "database");

//set the posted variables to convenient names


$field = $_POST['propertytype'];
$rent_min = $_POST['rent_min'];
$rent_max = $_POST['rent_max'];
$bedrooms_min = $_POST['bedrooms_min'];
$bedrooms_max = $_POST['bedrooms_max'];

//create the query
if (isset($_POST['keyword']) || isset($_POST['propertytype']) || isset($_POST['rent_min']) || isset($_POST['rent_max']) || isset($_POST['bedrooms_min']) || isset($_POST['bedrooms_max'])) {
	$result= $mysqldb->query("SELECT User_Name, Property_Details, To_Rent_Price FROM to_rent WHERE City= '$keyword'");

} else {
echo "Invalid search criteria has been entered";
}		

	//if records found, output firstname, lastname and email field



	if ($result->num_rows > 0) {
	while ($row = $result ->fetch_object())
	echo "$row-> User_Name, $row->To_Rent_Price ($row->Property_Details)<br />" ;

	} else {
	echo "No results found.";

	}
	}

	?>

</body>
</html>

Im a newbie studying this at University so do understand that im a novice. 🙂

    Can you give us a clue as to where line # 768 is in your code?

      Sorry totally forgot, here it is:
      echo "$row-> User_Name, $row->To_Rent_Price ($row->Property_Details)<br />" ;

      Thanks

        You need to get rid of the space between $row-> and User_Name.

          Thanks so much NogDog, i didnt even spot that.. Everything is working as sweet as a nut. Cheers buddy

            Write a Reply...