0

I keep getting this error when I try to process a shopping cart

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in

Here's the code section that I've been working on:

//STATEMENTS TO STORE ITEM ORDER
while($row = mysqli_fetch_array($r , MYSQLI_ASSOC)){
    $query = 
        "INSERT INTO order_contents (order_id,item_id,quantity,price)
        VALUES ($order_id, ".$row['item_id'].",".
        $_SESSION['cart'][$row['item_id']]['quantity'].",".
        $_SESSION['cart'][$row['item_id']]['price'].")";

    $result = mysqli_query($dbc,$query) or die (mysqli_error($dbc));
}

//CLOSE DB
mysqli_close($dbc);

//MESSAGE
echo "<p>Thanks for your order.<br/>
Your order number is #".$order_id."</p>";
$_SESSION['cart'] = NULL;
}

Any ideas? Thanks

Luigi Siri
  • 2,050
  • 2
  • 19
  • 27

1 Answers1

-1

You are running mysqli_fetch_array against the resource identifier $r but that value is only a boolean (true or false).

You need to have run a query before the while loop something like...

$r = mysqli_query($query, $dbc);

... where query is the sql that will generate the data to be used by mysql_fetch_array.

I hope this helps.

MMM
  • 7,013
  • 2
  • 23
  • 42
user466764
  • 1,179
  • 6
  • 7