-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.php
47 lines (36 loc) · 1.32 KB
/
store.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
<?php
// Connect to the database
$host = "localhost";
$username = "root";
$password = "";
$dbname = "bookdb";
$conn = mysqli_connect($host, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Get the form data
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$service = $_POST['service'];
$date = $_POST['date'];
$time = $_POST['time'];
// Insert the data into the "appointments" table
$appointment_query = "INSERT INTO appointments (name, email, phone,service, date, time) VALUES ('$name', '$email', '$phone','$service', '$date', '$time')";
mysqli_query($conn, $appointment_query);
// Check if the phone number exists in the "user" table
$check_phone_query = "SELECT * FROM user WHERE phone='$phone'";
$check_phone_result = mysqli_query($conn, $check_phone_query);
// If the phone number does not exist in the "user" table, insert the data into the table
if (mysqli_num_rows($check_phone_result) == 0) {
$user_query = "INSERT INTO user (name, email, phone) VALUES ('$name', '$email', '$phone')";
if (mysqli_query($conn, $user_query)) {
echo "Appointment Booked Successfully and New User Added";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
} else {
echo "Appointment Booked Successfully";
}
mysqli_close($conn);
?>