Error is showing up in my code :-
<?php
session_start();
$page = 'index.php';
$connection = mysqli_connect("localhost","root","","cart");
if(mysqli_connect_errno())
{
die("not connected to db ".mysqli_connect_error());
}
function product()
{
$sql = "select id,name,description,price from products where quantity > 0 order by id DESC" ;
$result = mysqli_query($connection,$sql);
if(mysqli_num_rows($result))
{
echo 'no products to display';
}
else
{
while($row = mysqli_fetch_assoc($result))
{
echo '<div class="boxed">'.$row['name'].'<br>'.$row['price'].'<br>'.$row['description'].'<br>'.'</div>';
}
}
}
?>
<html>
<head>
<title>
</title>
<script>
.boxed {
border: 1px solid green ;
}
</script>
</head>
<body>
<?php
product();
?>
</body>
</html>
Errors are :
Notice: Undefined variable: connection in /Applications/XAMPP/xamppfiles/htdocs/cart.php on line 11
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /Applications/XAMPP/xamppfiles/htdocs/cart.php on line 11
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /Applications/XAMPP/xamppfiles/htdocs/cart.php on line 12
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in /Applications/XAMPP/xamppfiles/htdocs/cart.php on line 18