I am trying to display products by pulling from mysql database. The code uses a function called getProductById that pulls products from the database. The idea is to match the product with the right price and then display the product with the function cartElement. I would like to thank you so much in advance for taking your time to help.
Note: Using PHP Version 7.3.11
Error Message:
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /Library/WebServer/Documents/J_Renzo_Mobile_Website_Draft/cart.php on line 90
My code:
            $total = 0;
            if(isset($_SESSION['cart']) && count($_SESSION['cart']) > 0) {
                foreach ($_SESSION['cart'] as $cartProduct) {
                    $product = $database->getProductById((int)$cartProduct['product_id']);
                    $price = match($cartProduct['option']) {
                        'exclusive' => $product['exclusive'],
                        'unlimited' => (int)$product['unlimited'],
                        'premium' => (int)$product['premium'],
                        default => (int)$product['basic'],
                    };
                    if (is_numeric($price)) {
                        $total += $price;
                    }
                    cartElement($product['product_image'], $product['product_name'],$price,$product['id']);
                    //break; I don't know if I need this...
                }
            } else {
                echo "<h5>Cart is empty.</h5>";
            }
Bind_param() statement giving errors:
//get product by id from database...
public function getProductById(int $id): array{
    //$stmt = $this->con->prepare('SELECT * FROM $tablename WHERE id = ?');
    $sql = "SELECT * FROM Productdb WHERE id = ?";
    $stmt = $this->con->prepare($sql);
    $stmt->bind_param("i", $id);
    $stmt->execute();
    $result = $stmt->get_result();
    return $result->fetch_assoc();
}
 
    