I have some basic shopping cart code to display all items in my carts session, the view_cart.php is displaying the error:
Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean in C:\wamp64\www\shopping_cart\shopping_cart\view_cart.php on line 72
I have only edited the index a little the code was working perfectly before, now I just can't seem to get rid of this error..?
this is line 72: I cant see the error: ..
<?php
//initialize total
$total = 0;
if (!empty($_SESSION['cart'])){
//connection
$conn = new mysqli('localhost', 'root', '', 'database');
//create array of initail qty which is 1
$index = 0;
if (!isset($_SESSION['qty_array'])) {
$_SESSION['qty_array'] = array_fill(0, count($_SESSION['cart']), 1);
}
$sql = "SELECT * FROM products WHERE id IN (" . implode(',', $_SESSION['cart']) . ")";
$query = $conn->query($sql);
while ($row = $query->fetch_assoc()){
?>