-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfirm.php
68 lines (56 loc) · 2.11 KB
/
confirm.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
<?php
ini_set('display_errors', 1); error_reporting(E_ALL);
$db_host = 'localhost:3307';
$db_user = 'root';
$db_pass = '';
$db_name = 'testdb';
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
session_start();
if(isset($_POST['paymentpage'])) {
$tour_id = $_POST['tour_id'];
$userid = $_SESSION['id'];
$sql = "INSERT INTO paid (tourid, userid) VALUES ('$tour_id', '$userid')";
$result = mysqli_query($conn, $sql);
if ($result) {
$sql = "SELECT tours.name, tours.price, cards.cardnumber, cards.phonenumber, cards.name
FROM tours
INNER JOIN cards ON tours.userid = cards.userid
WHERE tours.id = '$tour_id' AND cards.userid = '$userid'";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
// display the information and confirmation button
echo "<h2>Confirm Payment</h2>";
echo "<p>Tour Name: ".$row['name']."</p>";
echo "<p>Price: ".$row['price']."</p>";
echo "<p>Card Number: ".$row['cardnumber']."</p>";
echo "<p>Phone Number: ".$row['phonenumber']."</p>";
echo "<p>Name on Card: ".$row['name']."</p>";
echo "<form action='' method='POST'>";
echo "<input type='submit' name='paymentconfirmed' value='Confirm Payment'>";
echo "</form>";
} else {
echo "No matching records found.";
}
} else {
echo "Error: " . mysqli_error($conn);
}
}
if(isset($_POST['paymentconfirmed'])) {
$tour_id = $_POST['tour_id'];
$userid = $_SESSION['id'];
$sql = "INSERT INTO paid (tourid, userid) VALUES ('$tour_id', '$userid')";
$result = mysqli_query($conn, $sql);
if($result) {
// display the success message in a popup
echo "<script>alert('Booking Successful!')</script>";
} else {
echo "Error: " . mysqli_error($conn);
}
}
mysqli_close($conn);
?>