-
Notifications
You must be signed in to change notification settings - Fork 0
/
connect.php
115 lines (109 loc) · 3.43 KB
/
connect.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
<!--
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$mobileno = $_POST['mobileno'];
$city = $_POST['city'];
$des = $_POST['des'];
$people = $_POST['people'];
//database connection
// $conn = new mysqli('localhost', 'root','','booking');
// if($conn->connect_error){
// die('connection failed : ' .$conn->connection_error)
// }
// else{
// $stmt = $conn->prepare("insert into form(firstname,lastname,email,mobileno,city,des,people) values(?. ?, ?, ?, ?, ?, ?, ?)");
// $stmt->bind_param("sssisss",$firstname, $lastname, $email, $mobileno,$city, $des. $people);
// $stmt->execute();
// echo"booking Successfull";
// $stmt->close();
// $conn->close();
// }
// // ?>
//
// $firstname = filter_input(INPUT_POST, 'firstname');
// $lastname = filter_input(INPUT_POST, 'lastname');
// $email = filter_input(INPUT_POST, 'email');
// $mobileno = filter_input(INPUT_POST, 'mobileno');
// $city = filter_input(INPUT_POST, 'city');
// $des = filter_input(INPUT_POST, 'des');
// $people = filter_input(INPUT_POST, 'people');
// if (!empty($firstname)){
// if (!empty($lastname)){
// $host = "localhost";
// $dbusername = "root";
// $dbpassword = "";
// $dbname = "booking";
// // Create connection
// $conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);
// if (mysqli_connect_error()){
// die('Connect Error ('. mysqli_connect_errno() .') '
// . mysqli_connect_error());
// }
// else{
// $sql = "INSERT INTO form (firstname, lastname,email,mobileno,city,des,people)
// values ('$firstname','$lastname','$email','$mobileno','$city','$des','$people')";
// if ($conn->query($sql)){
// echo "New record is inserted sucessfully";
// }
// else{
// echo "Error: ". $sql ."
// ". $conn->error;
// }
// $conn->close();
// }
// }
// else{
// echo "Password should not be empty";
// die();
// }
// }
// else{
// echo "Username should not be empty";
// die();
// }
// ?> //
<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$mobileno = $_POST['mobileno'];
$city = $_POST['city'];
$des = $_POST['des'];
$people = $_POST['people'];
if (!empty($firstname) || !empty($lastname) || !empty($email) || !empty($mobileno) || !empty($city) || !empty($des) || !empty($people)) {
$host = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbname = "booking";
//create connection
$conn = new mysql($host, $dbUsername, $dbPassword, $dbname);
if (mysqli_connect_error()) {
die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error());
} else {
$SELECT = "SELECT email From register Where email = ? Limit 50";
$INSERT = "INSERT Into form (firstname, lastname, email, mobileno, city, des,people) values(?, ?, ?, ?, ?, ?,?)";
//Prepare statement
$stmt = $conn->prepare($SELECT);
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($email);
$stmt->store_result();
$rnum = $stmt->num_rows;
if ($rnum==0) {
$stmt->close();
$stmt = $conn->prepare($INSERT);
$stmt->bind_param("sssisss", $firstname, $lastname, $email, $mobileno, $city, $des, $people );
$stmt->execute();
echo "New record inserted sucessfully";
} else {
echo "Someone already register using this email";
}
$stmt->close();
$conn->close();
}
} else {
echo "All field are required";
die();
}
?>