I currently have a working cart system that when clicking "addToCart" the product code is stored inside $_SESSION['cart'] array and then printed out in a drop down menu, if no value is stored then it prints "No items in cart". This works fully fine but when I try to use the product code to pull the rest of the items data from the database I get 500 internal server error, however this method of connection to the database works perfectly fine, Any advice would be grateful.
<div class="dropDownCart">
<button onclick="dropDownCart()" class="dropDownCartBtn">Cart</button>
<div id="dropDownCartID" class="dropDownCartContent">
<?php
if ($_SESSION['cart'] === null) {
echo "<span class='noItems'>No items in cart</span>";
} elseif (!isset($_SESSION['cart'])) {
echo "<span class='noItems'>No items in cart</span>";
} else {
require_once("dbConnection.php");
$dbConn = getConnection();
foreach ($_SESSION['cart'] as $productCode) {
$sqlQuery = "SELECT Name FROM studentcomforts WHERE Product_Code = $productCode";
$queryResult = $dbConn->query($sqlQuery);
$rowObj = $queryResult->fetchObject();
echo "<span class='cartItem'>
$rowObj->Name
</span>";
}
}
?>