-
Notifications
You must be signed in to change notification settings - Fork 0
/
mafundiProcess.php
executable file
·98 lines (90 loc) · 2.16 KB
/
mafundiProcess.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.error{
color: #FF0000;
}
</style>
</head>
<body>
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "phpmyadmin";
//Defining variables and setting to empty values.
$nameErr = $phoneErr = $emailErr = "";
$name = $phone = $email = $service = $location = $floorno = $houseno = $time = $date = $addesc = "";
$conn = new mysqli("localhost", "root", "", "phpmyadmin");
if($conn -> connect_error)
{
die("Connection Failed!!" . $conn -> connect_error);
}
//Conditionals Validating Name.
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(empty($_POST["name"])){
$nameErr = "Your name is required! ";
}else{
$name = testy($_POST["name"]);
if(!preg_match("/^[a-zA-Z]*$/", $name)){
$nameErr = "Only letters and white spaces allowed";
}
}
//Validate Phone.
if(empty($_POST["phone"]))
{
$phoneErr = "Enter your number for contacting purposes!";
}else{
$phone = testy($_POST["phone"]);
}
//Validating Email
if(empty($_POST["email"]))
{
$emailErr = "Your email is required!";
}else
{
$email = testy($_POST["email"]);
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$emailErr = "Invalid email address!";
}
}
//Validating Commment Section
if(empty($_POST["comment"]))
{
$comment = "";
}else{
$comment = testy($_POST["comment"]);
}
}
function testy($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$sql = "INSERT INTO customerdetailz VALUES('".
$name ."','".
$phone ."','".
$email ."','".
$service ."','".
$location ."','".
$floorno ."','".
$houseno ."','".
$time ."','".
$date . "')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
</body>
</html>