Hello.
I have a little problem.
I am stuck and don’t know why it is not possible to retrieve the order_details from the database and reflect it on the relevant page.
Order detail page shows error
Notice: Undefined variable: order_details in /opt/lampp/htdocs/e-shop/order_details.php on line 50
Fatal error: Uncaught Error: Call to a member function fetch_assoc() on null in /opt/lampp/htdocs/e-shop/order_details.php:50 Stack trace: #0 {main} thrown in /opt/lampp/htdocs/ e-shop/order_details.php on line 50
attached picture.
order_details.php
<?php
session_start();
/*
not paid
paid
shipped
delivered
*/
include 'server/connection.php';
include 'layouts/header.php';
if (isset($_POST['order_details_btn']) && isset($_POST['order_id'])) {
$order_id = $_POST['order_id'];
$order_status = $_POST['order_status'];
$stmt = $conn->prepare("SELECT * FROM order_items WHERE order_id = ?");
$stmt->bind_param('i', $order_id);
$stmt->execute();
$order_details = $stmt->get_result();
} else {
//header('location: account.php');
}
?>
<!-- Orders -->
<section id="orders" class="orders container my-5 py-5">
<div class="container mt-5">
<h2 class="form-weight-bold text-center">Order details</h2>
<hr class="mx-auto ">
</div>
<table class="mt-5 pt-5 mx-auto" >
<tr>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
</tr>
<?php while ($row = $order_details->fetch_assoc()) {?>
<tr>
<td>
<div class="product-info">
<img src="assets/imgs/<?php echo $row['product_image']; ?>"/>
<div>
<p class="pt-3"><?php echo $row['product_name']; ?></p>
</div>
</div>
</td>
<td>
<span>€<?php echo $row['product_price']; ?></span>
</td>
<td>
<span><?php echo $row['product_quantity']; ?></span>
</td>
</tr>
<?php }?>
</table>
<?php if ($order_status == "not paid") {?>
<form style="float: right;" method="POST" action="payment.php">
<input type="hidden" name="order_total_price" value="<?php echo $order_total_price; ?>"/>
<input type="hidden" name="order_status" value="<?php echo $order_status; ?>"/>
<input type="submit" name="total_pay_btn" class="btn btn-primary" value="Pay Now"/>
</form>
<?php }?>
</section>
<?php include 'layouts/footer.php';?>