0

I am trying to fetch a row from my mysql DB using mysqli query.

PHP

$_SESSION['orderID'] = "632";
$orID = $_SESSION['orderID'];
$sql = $db->prepare('SELECT * FROM order_list WHERE order_id = ? ');
$sql->bind_param('s',$orID);
$sql->execute();
while($row = $sql->fetch()) 
{
   $productid = $row[0];
   $name = $row[1];
   echo $price = $row[2];

}

give no error in console and no result,

I have been trying to check the answers on stack overflow, I also googled it but all the suggestions gives me the same error.

I am pretty new with mysqli, your help will be highly appreciated

Kissa Mia
  • 297
  • 8
  • 23

1 Answers1

1

mysqli_fetch_array is a mysqli_result method not a mysqli_stmt one

You could use ->fetch() upon a mysqli_stmt

So basically your code could change that way

while($sql->fetch()) {
 //do something
}

but you need to call bind_result() before looping (otherwise you can't access returned values)

DonCallisto
  • 29,419
  • 9
  • 72
  • 100