当我运行代码时,下面的代码没有显示总价,它只返回“总价:£”。任何帮助都会有所帮助。
<?php
// Create a PDO connection to the database
$dbh = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME, DB_USER,
DB_PASS);
$id = $_POST['id'];
// Prepare a SQL statement to select the total of the price column
$stmt = $dbh->prepare('SELECT SUM(hotel_price) as total FROM products
WHERE user_id = :user_id');
// Execute the statement
$stmt->execute([
"user_id" => $_SESSION['user_data']['user_id'],
]);
// Fetch the total as an associative array
$total = $stmt->fetch(PDO::FETCH_ASSOC)['total'];
// Display the total
echo "Total price: £$total";
?>