-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
53 lines (52 loc) · 1.6 KB
/
test.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
<?php
include 'db_connection.php';
// Create connection
$conn = OpenCon();
// Check connection
$first=$_POST["fname"];
if (empty($_POST["fname"])) {
$nameErr = "first Name is required";
} else {
$name = test_input($_POST["fname"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
$last=$_POST["lname"];
if (empty($_POST["lname"])) {
$nameErr = "last Name is required";
} else {
$name = test_input($_POST["lname"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
$user=$_POST["uname"];
if (empty($_POST["uname"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["uname"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
$pass=$_POST["pass"];
$sql = "INSERT INTO user_details (firstname, lastname, username,password)
VALUES ('$first', '$last', '$user','$pass')";
if ($conn->query($sql) === TRUE) {
echo "<script>window.alert('New record created successfully');</script>";
echo "<body>welcome to the world of our travels</body>";
} else {
echo "<script>window.alert('this username already exists');</script>";
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
CloseCon($conn);
?>