-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.php
More file actions
50 lines (48 loc) · 1.38 KB
/
action.php
File metadata and controls
50 lines (48 loc) · 1.38 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$country = $_POST['country'];
$message = $_POST['message'];
if (!empty($firstname) || !empty($lastname) || !empty($email) || !empty($gender) || !empty($country) || !empty($message) )
{
$host = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "travelmania";
// Create connection
$conn = mysqli_connect ($host, $dbusername, $dbpassword, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
else{
$SELECT = "SELECT email From contact Where email = ? Limit 1";
$INSERT = "INSERT Into contact (firstname , lastname , email , gender , country , message)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;
//checking username
if ($rnum==0) {
$stmt->close();
$stmt = $conn->prepare($INSERT);
$stmt->bind_param("ssssss", $firstname , $lastname , $email , $gender , $country , $message);
$stmt->execute();
echo "Thanks for contacting us";
}
else {
echo "Someone already register using this email";
}
$stmt->close();
$conn->close();
}
}
else {
echo "All field are required";
die();
}
?>