-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbook_car.php
150 lines (119 loc) · 5.38 KB
/
book_car.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
include('includes/config.php');
session_start();
error_reporting(0);
if (isset($_SESSION['admin_loggedin']) && $_SESSION['admin_loggedin'] == true) {
header("location:/admin/dashboard.php");
exit;
}
?>
<!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="assets/css/style.css">
<link rel="stylesheet" href="assets/css/sign_up.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="assets/css/bookingpage.css">
<title>Document</title>
</head>
<body>
<?php
include("includes/header.php");
$vhid = intval($_GET['vhid']);
$sql = "SELECT * from tbcars where id=:vhid";
$query = $dbh->prepare($sql);
$query->bindParam(':vhid', $vhid, PDO::PARAM_INT);
$query->execute();
$results = $query->fetchAll(PDO::FETCH_OBJ);
$cnt = 1;
if ($query->rowCount() > 0) {
foreach ($results as $car) {
?>
<section class="car-section">
<div class="car-details">
<div class="car-image">
<img src="admin\img\vehicleimages\<?php echo $car->vimg ?>" alt="car">
</div>
<div class="text-car">
<div class="group">
<div class="car-item car-model">
<H3>MODEL: </H3>
<H5><?php echo $car->model ?></H5>
</div>
<div class="car-item car-number">
<H3>NUMBER: </H3>
<H5><?php echo $car->veh_number ?></H5>
</div>
</div>
<div class="group">
<div class="car-item car-seats">
<H3>SEATS: </H3>
<H5><?php echo $car->seats ?></H5>
</div>
<div class="car-item car-rent">
<H3>RENT/DAY: </H3>
<H5><?php echo $car->rent ?>$</H5>
</div>
</div>
</div>
</div>
<div class="card book-form container">
<div class="card-header">
<h2>Input User</h2>
</div>
<div class="card-body">
<form method="post" action="book_car.php">
<label for="email">From:</label>
<input type="text" id="email" placeholder="From Date(dd/mm/yyyy)" name="fromdate" required>
<label for="phone">To:</label>
<input type="text" id="phone" placeholder="To Date(dd/mm/yyyy)" name="todate" required>
<label for="name">Message:</label>
<input type="text" placeholder="message" id="name" name="message" required>
<input type="hidden" name="car-id" value="<?php echo $vhid ?>" required>
<div class="card-footer">
<button type="submit" class=" btn btn-danger book-btn">Book</button>
</div>
</form>
</div>
</div>
</section>
<?php
}
}
?>
<?php
if ($_POST) {
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
$username = $_SESSION['user'];
$fromdate = $_POST['fromdate'];
$todate = $_POST['todate'];
$message = $_POST['message'];
$veh_id = $_POST['car-id'];
$sql = "INSERT INTO bookings (username, vehicle_id, from_date, to_date, message, status) VALUES (:username,:vehicle_id,:fromdate,:todate, :message, 'pending')";
$query = $dbh->prepare($sql);
$query->bindParam(':username', $username, PDO::PARAM_STR);
$query->bindParam(':vehicle_id', $veh_id, PDO::PARAM_STR);
$query->bindParam(':fromdate', $fromdate, PDO::PARAM_STR);
$query->bindParam(':todate', $todate, PDO::PARAM_STR);
$query->bindParam(':message', $message, PDO::PARAM_STR);
$query->execute();
$lastInsertId = $dbh->lastInsertId();
if ($lastInsertId) {
// Once the task is successfully completed, set a session variable
$_SESSION['task_success'] = true;
// Redirect the user to another route
header("Location: index.php");
exit; // Make sure to exit after the redirect
} else {
echo "<script>alert('Something went wrong. Please try again');</script>";
}
} else {
$_SESSION['login-msg'] = true;
header("Location: user_login.php");
}
}
?>
</body>
</html>