0

I'm using core php, Actually i'm getting post value from submitting my form,i'm going to pass that variable to like query at the time showing issue like :

Fatal error: Cannot use object of type mysqli_result as array in C:\xampp.

I don't know what is the mistake I did please help me.

Here's my code:

if(isset($_POST['list'])){ 
     //-----from post value----//
      $location_type =$_POST['list'];
      $arr = explode(' ',trim($location_type));
      $listing=$arr[0];
      $all_location ="select * from tbl_master_property where pg_address like '%$listing%'";
      $location_result=$conn->query($all_location);
      while($row=mysqli_fetch_assoc($location_result)){ 
      $location_result[] = $row['pg_address'];
      }
      echo "<pre>";print_r($location_result);die;
  } 
1
  • Raj the error message will definitly telling you line number too. please specify which line is causing issue Commented Mar 16, 2018 at 5:01

1 Answer 1

0

Problem is you are trying to over-write your mysqli_result variable$location_result inside while() loop.

You need to take a separate array variable to get all the values.

Do like below (and please read comments inside code carefully ):-

 if(isset($_POST['list'])){ 
      $location_type =$_POST['list'];

      $arr = explode(' ',trim($location_type));

      $listing=$arr[0];

      $all_location ="select * from tbl_master_property where pg_address like '%$listing%'";

      $all_location_result = [];//create an array variable
      $location_result=$conn->query($all_location);
      while($row=$location_result->fetch_assoc()){ // try not to mix oop way with procedural way, not a good practic
        $all_location_result[] = $row['pg_address']; // assign values to array variable
      }
      echo "<pre>";print_r($all_location_result);// print array variable
  }

Note:- Youe query code is wide-open for SQL INJECTION so try to use prepared statements

Reference:-

mysqli::prepare

PDO::prepare

Sign up to request clarification or add additional context in comments.

1 Comment

@Raj glad to help you :):)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.