Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
session_start();
if (!isset($_SESSION['admin']) || $_SESSION['admin'] !== true) {
header("Location: admin_login.php");
exit;
}
include 'connectie.php';
// Function to update order status
if(isset($_POST['update_status'])) {
$order_id = $_POST['order_id'];
$new_status = $_POST['new_status'];
// Update order status in the database
$sql_update = "UPDATE orders SET status = :new_status WHERE id = :order_id";
$stmt_update = $conn->prepare($sql_update);
$stmt_update->bindParam(':new_status', $new_status);
$stmt_update->bindParam(':order_id', $order_id);
$stmt_update->execute();
}
$sql = "SELECT * FROM orders";
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Pizzaknaller | Admin Dashboard</title>
</head>
<body>
<h1>Admin Dashboard</h1>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
<th>Address</th>
<th>Pizza</th>
<th>Quantity</th>
<th>Order Date</th>
<th>Status</th> <!-- Added column for order status -->
<th>Action</th> <!-- Added column for action buttons -->
</tr>
<?php
$num_rows = $result->rowCount();
if ($num_rows) {
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
echo "<tr>";
echo "<td>" . $row["id"] . "</td>";
echo "<td>" . $row["name"] . "</td>";
echo "<td>" . $row["phone"] . "</td>";
echo "<td>" . $row["email"] . "</td>";
echo "<td>" . $row["address"] . "</td>";
echo "<td>" . $row["pizza"] . "</td>";
echo "<td>" . $row["quantity"] . "</td>";
echo "<td>" . $row["order_date"] . "</td>";
echo "<td>" . $row["status"] . "</td>"; // Display order status
echo "<td>";
// Add buttons to update order status
echo "<form action='' method='POST'>";
echo "<input type='hidden' name='order_id' value='" . $row['id'] . "'>";
echo "<select name='new_status'>";
echo "<option value='preparing'>Preparing</option>";
echo "<option value='cooking'>Cooking</option>";
echo "<option value='delivering'>Delivering</option>";
echo "</select>";
echo "<input type='submit' name='update_status' value='Update'>";
echo "</form>";
echo "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='10'>No orders found</td></tr>";
}
// Function to update order status
if(isset($_POST['update_status'])) {
$order_id = $_POST['order_id'];
$new_status = $_POST['new_status'];
// Update order status in the database
$sql_update = "UPDATE orders SET status = :new_status WHERE id = :order_id";
$stmt_update = $conn->prepare($sql_update);
$stmt_update->bindParam(':new_status', $new_status);
$stmt_update->bindParam(':order_id', $order_id);
$stmt_update->execute();
// Check if the update was successful
if($stmt_update->rowCount() > 0) {
echo "<p>Order status updated successfully.</p>";
}
}
?>
</table>
<a href="admin_logout.php">Logout</a>
</body>
</html>