-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontact.php
134 lines (127 loc) · 3.14 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?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);
$errorf = "";
$errorl = "";
$errore = "";
$errorb = "";
if (empty($fname)) {
$errorf = "First name must not be empty !";
}
if (empty($lname)) {
$errorl = "Last name must not be empty !";
}
if (empty($email)) {
$errore = "Email must not be empty !";
}
if (empty($body)) {
$errorb = "Body must not be empty !";
/*
if (empty($fname)) {
$error = "First name must not be empty !";
} elseif (!filter_var($fname, FILTER_SANITIZE_SPECIAL_CHARS)) {
$error = "Invalid name !";
} elseif (empty($lname)) {
$error = "Last name must not be empty !";
} elseif (empty($email)) {
$error = "Email 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 sent Successfully !";
}else {
$error = "Message not sent !";
}
}
}
?>
<style type="text/css">
.cuserror{color: red; float: left;}
</style>
<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>
<?php
if (isset($errorf)) {
echo "<span class='cuserror'>$errorf</span>";
}
?>
<input type="text" name="firstname" placeholder="Enter first name" />
</td>
</tr>
<tr>
<td>Your Last Name:</td>
<td>
<?php
if (isset($errorl)) {
echo "<span class='cuserror'>$errorl</span>";
}
?>
<input type="text" name="lastname" placeholder="Enter Last name" />
</td>
</tr>
<tr>
<td>Your Email Address:</td>
<td>
<?php
if (isset($errore)) {
echo "<span class='cuserror'>$errore</span>";
}
?>
<input type="text" name="email" placeholder="Enter Email Address" />
</td>
</tr>
<tr>
<td>Your Message:</td>
<td>
<?php
if (isset($errorb)) {
echo "<span class='cuserror'>$errorb</span>";
}
?>
<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';?>