prepare( 'SELECT o.id FROM orders o ' . 'JOIN driver_assignments da ON o.id = da.order_id ' . 'WHERE o.id = ? AND da.driver_id = ?' ); $check_stmt->execute([$order_id, $driver_id]); $assignment = $check_stmt->fetch(); if (!$assignment) { header('Location: index.php?error=You are not authorized to update this order.'); exit; } // Update the order status $update_stmt = $pdo->prepare('UPDATE orders SET status = ? WHERE id = ?'); if ($update_stmt->execute([$status, $order_id])) { header('Location: index.php?success=Order status updated successfully.'); exit; } else { header('Location: index.php?error=Failed to update order status.'); exit; } } catch (PDOException $e) { header('Location: index.php?error=A database error occurred.'); exit; } } else { header('Location: index.php'); exit; } ?>