-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser_book_tour.php
38 lines (32 loc) · 1012 Bytes
/
user_book_tour.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
<?php
// Start the session
session_start();
// Check if the user is logged in
if (!isset($_SESSION['userid'])) {
// If the user is not logged in, redirect to the login page
header("Location: login.php");
exit();
}
// Get the tour ID from the URL
$tourid = $_GET['tourid'];
// Connect to the database
$servername = "localhost:3307";
$username = "username";
$password = "";
$dbname = "testdb";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Prepare and execute the SQL statement to insert the booking
$stmt = $conn->prepare("INSERT INTO bookings (tourid, userid) VALUES (:tourid, :userid)");
$stmt->bindParam(':tourid', $tourid);
$stmt->bindParam(':userid', $_SESSION['userid']);
$stmt->execute();
// Redirect to the user dashboard
header("Location: userdashboard.php");
exit();
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
?>