-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookingProcess.php
More file actions
30 lines (26 loc) · 1.27 KB
/
Copy pathbookingProcess.php
File metadata and controls
30 lines (26 loc) · 1.27 KB
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
<?php
session_start();
include "connection.php";
$username = $_SESSION['username'];
$query = "SELECT * FROM users WHERE username = '$username'";
$result = mysqli_query($connect, $query);
$row = mysqli_fetch_assoc($result);
$tourist_id = $row['user_id'];
$booking_date = $_POST['booking_date'];
$product_id = $_GET['product_id'];
$quantity = $_POST['quantity'];
$booking_days = $_POST['booking_days'];
$query = "INSERT INTO bookings (tourist_id, booking_date, product_id, quantity, booking_days) VALUES
($tourist_id, '$booking_date', $product_id, $quantity, $booking_days);";
if (mysqli_query($connect, $query)) {
$query = "UPDATE products SET product_stock = product_stock - 1 WHERE product_id = $product_id;";
if (mysqli_query($connect, $query)) {
echo "<script>alert('Berhasil booking." . mysqli_error($connect) . "'); window.location.href='homeUser.php'</script>";
} else {
echo "gagal tumbas<br>";
echo mysqli_error($connect);
}
} else {
echo "<script>alert('Gabisa beli dong gengs." . mysqli_error($connect) . "'); window.location.href='booking.html'</script>";
}
?>