34830-vm/trip-setup.php
Flatlogic Bot 6461eb73ca herway
2025-10-09 15:53:22 +00:00

74 lines
3.0 KiB
PHP

<?php
require_once 'db/config.php';
require_once 'includes/header.php';
// Redirect to login if user is not authenticated
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit();
}
$error_message = '';
$success_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$destination = trim($_POST['destination']);
$trip_time = trim($_POST['trip_time']);
if (empty($destination) || empty($trip_time)) {
$error_message = 'Please fill in all fields.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare("INSERT INTO trips (user_id, destination, trip_time) VALUES (:user_id, :destination, :trip_time)");
$stmt->bindParam(':user_id', $_SESSION['user_id'], PDO::PARAM_INT);
$stmt->bindParam(':destination', $destination, PDO::PARAM_STR);
$stmt->bindParam(':trip_time', $trip_time, PDO::PARAM_STR);
if ($stmt->execute()) {
header('Location: my-trips.php?status=success');
exit();
} else {
$error_message = 'Failed to save the trip. Please try again.';
}
} catch (PDOException $e) {
$error_message = 'Database error: ' . $e->getMessage();
}
}
}
?>
<main class="py-5">
<section id="trip-setup" class="container">
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="card p-4 p-md-5">
<h1 class="text-center mb-4">Plan Your Trip</h1>
<p class="text-center text-muted mb-5">Enter your destination and travel time to find verified travel companions.</p>
<?php if (!empty($error_message)): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
<?php endif; ?>
<form action="trip-setup.php" method="post">
<div class="mb-4">
<label for="destination" class="form-label fs-5">Where are you going?</label>
<input type="text" class="form-control form-control-lg" id="destination" name="destination" placeholder="e.g., 'Mumbai', 'Delhi Airport Terminal 3'" required>
</div>
<div class="mb-4">
<label for="trip_time" class="form-label fs-5">When are you traveling?</label>
<input type="datetime-local" class="form-control form-control-lg" id="trip_time" name="trip_time" required>
</div>
<div class="text-center mt-5">
<button type="submit" class="btn btn-primary btn-lg px-5">Save Trip</button>
</div>
</form>
</div>
</div>
</div>
</section>
</main>
<?php require_once 'includes/footer.php'; ?>