-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.php
93 lines (83 loc) · 2.66 KB
/
contact.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
<?php include 'inc/header.php' ?>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$fname = $fm->validation($_POST['firstname']);
$lname = $fm->validation($_POST['lastname']);
$email = $fm->validation($_POST['email']);
$body = $fm->validation($_POST['body']);
$fname = mysqli_real_escape_string($db->link, $fname);
$lname = mysqli_real_escape_string($db->link, $lname);
$email = mysqli_real_escape_string($db->link, $email);
$body = mysqli_real_escape_string($db->link, $body);
$error = "";
if (empty($fname)) {
$error = "Fist name must not be empty!";
} elseif (empty($lname)) {
$error = "Last name must not be empty!";
} elseif (empty($email)) {
$error = "Email field must not be empty!";
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error = "Invalid Email Address!";
} elseif (empty($body)) {
$error = "Message field must not be empty!";
} else {
$query = "INSERT INTO tbl_contact (firstname, lastname, email, body) VALUES ('$fname', '$lname', '$email', '$body')";
$inserted_rows = $db->insert($query);
if ($inserted_rows) {
$msg = "Message send succcessfully.";
} else {
$error = "Message not sent!";
}
}
}
?>
<div class="contentsection contemplete clear">
<div class="maincontent clear">
<div class="about">
<h2>Contact us</h2>
<?php
if (isset($error)) {
echo "<span style='color:red'>$error</span>";
}
if (isset($msg)) {
echo "<span style='color:green'>$msg</span>";
}
?>
<form action="" method="post">
<table>
<tr>
<td>Your First Name:</td>
<td>
<input type="text" name="firstname" placeholder="Enter first name" required="1"/>
</td>
</tr>
<tr>
<td>Your Last Name:</td>
<td>
<input type="text" name="lastname" placeholder="Enter Last name" required="1"/>
</td>
</tr>
<tr>
<td>Your Email Address:</td>
<td>
<input type="email" name="email" placeholder="Enter Email Address" required="1"/>
</td>
</tr>
<tr>
<td>Your Message:</td>
<td>
<textarea name="body"></textarea>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="submit" value="Send"/>
</td>
</tr>
</table>
<form>
</div>
</div>
<?php include 'inc/sidebar.php'; ?>
<?php include 'inc/footer.php'; ?>