I'm trying to create a product page based on the passed in ID from the URL, I get this error:
Fatal error: Cannot use object of type Product as array in E:\xampp\htdocs\DiamondCommerce\product.php on line 4
<?php
//URL would be diamond.dev/product?{id}
require_once 'dbconfig.php';
$product_id = $_GET[$product['product_id']];
$currentProduct = $DB_con->prepare("SELECT * FROM products where product_id = :this_product_id LIMIT 1");
$product_id->bindParam(":this_product_id" , $product_id);
$currentProduct->execute();
$currentProductInfo = $currentProduct->fetch(PDO::FETCH_ASSOC);
//if isset for button
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title><?php $currentProduct['product_name']?></title>
</head>
<body>
<?php
foreach($currentProductInfo as $currentProduct)
{
echo '<p>',$currentProduct['product_name'],'</p>';
echo '<p>',$currentProduct['product_description'],'</p>';
echo '<p>',$currentProduct['product_price'],'</p>';
echo '<p>',$currentProduct['product_image'],'</p>';
echo '<a href="#" class="btn btn-primary" name="addToBasket">Add to Basket</a>';
}
?>
</body>
</html>
The URL looks fine (example: http://diamond.dev/product.php?id=5), which is what I want, but I don't know what is causing this error. Greatly appreciate any help.