Edit- >>>>>> Ok this works fine if I use another browser but I am trying to use it in chrome and I have this error. How comes it is like this? I am not understanding on what I can do. I have looked at the other question to help but still not understanding!
I am creating a shopping cart following a tutorial on youtube, hes using mysql but I have to mysqli for the work I am doing. I keep getting the following error:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\Shoppingcart\index.php on line 35
My code for the page is as follows:
<html>
<head>
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/style.css">
<title>Shopping Cart</title>
</head>
<body>
<div id="container">
<div id="main"><?php require ($page . ".php"); ?></div>
<div id="sidebar"><h1>Cart</h1>
<?php
if(isset($_SESSION['cart'])){
$sql = "SELECT * FROM products WHERE id_products IN(";
foreach($_SESSION['cart'] as $id => $value){
$sql .= $id. ",";
}
$sql = substr($sql, 0,-1) . ") ORDER BY id_products ASC";
$query = mysqli_query($connction, $sql);
while($row = mysqli_fetch_array($query)){
?>
<p><?php echo $row['name']; echo " x " . $_SESSION['cart'][$row['id_products']]['quantity'];?></p>
<?php
}
}else{
echo "<p>Your cart is empty.<br> Please add some items</p>";
}
echo '<a href="index.php?page=cart">Go to cart</a>';
?>
</div>
</div>
</body>
</html>
Line 35 where the error occurs in the code is:
while($row = mysqli_fetch_array($query)){
Can anyone give me an idea what is causing it I have tried asking the person who created the video but as it was made roughly 6 years ago he is most probably not there.
Many thanks