34830-vm/trip-setup.php
Flatlogic Bot 952205e132 herway
2025-10-09 14:48:50 +00:00

139 lines
6.1 KiB
PHP

<?php
session_start();
require_once 'db/config.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();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Trip Setup - HerWay</title>
<meta name="description" content="Set up your trip and find safe travel companions with HerWay.">
<!-- Google Fonts: Poppins -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<!-- Header -->
<header class="navbar navbar-expand-lg navbar-light bg-light sticky-top">
<div class="container">
<a class="navbar-brand fw-bold" href="index.php">HerWay</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="index.php#features">Features</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#contact">Contact</a></li>
<?php if (isset($_SESSION['user_id'])): ?>
<li class="nav-item"><a class="nav-link" href="my-trips.php">My Trips</a></li>
<li class="nav-item"><a class="btn btn-outline-primary ms-lg-3" href="logout.php">Logout</a></li>
<?php else: ?>
<li class="nav-item"><a class="nav-link" href="login.php">Login</a></li>
<li class="nav-item"><a class="btn btn-primary ms-lg-3" href="register.php">Sign Up</a></li>
<?php endif; ?>
</ul>
</div>
</div>
</header>
<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>
<!-- Footer -->
<footer class="py-4 bg-dark text-white">
<div class="container text-center">
<p>&copy; <?php echo date("Y"); ?> HerWay. All Rights Reserved.</p>
<p>
<a href="#" class="text-white">Privacy Policy</a> |
<a href="#" class="text-white">Terms of Service</a>
</p>
</div>
</footer>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<!-- Custom JS -->
<script src="assets/js/main.js"></script>
</body>
</html>