-
Notifications
You must be signed in to change notification settings - Fork 5
/
ca_validate.php
69 lines (53 loc) · 2.38 KB
/
ca_validate.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
<?php
$name =$email =$contact =$college =$link="";
$nameErr=$emailErr=$contactErr=$collegeErr=$linkErr="";
$conn = new mysqli("localhost", "root", "", "nitrutsav");
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
// Name validation
if (empty($_POST["name"])) { $nameErr = "Name is empty!"; }
else if(!preg_match("/^[a-zA-Z ]*$/",$_POST["name"])){
$name = test($_POST["name"]);
$nameErr ="Only letters and white space allowed"; }
else{ $name = test($_POST["name"]); }
// Email Validation
$val=$conn->query("SELECT email FROM ca WHERE email='".$_POST["email"]."'");
if (empty($_POST["email"])) { $emailErr = "Email is empty!"; }
else if (!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
$email = test($_POST["email"]);
$emailErr = "Enter a valid email."; }
else if ($val->num_rows>0) {
$email = test($_POST["email"]);
$emailErr = "This email is already registered"; }
else{ $email = test($_POST["email"]); }
// contact validation
if (empty($_POST["contact"])) { $contactErr = "contact number is empty!"; }
else if (!preg_match("/^[0-9]{10}+$/", $_POST["contact"])) {
$contact = test($_POST["contact"]);
$contactErr = "enter a valid contact number"; }
else{ $contact = test($_POST["contact"]); }
// Institute name validation
if (empty($_POST["college"])) { $collegeErr = "institute name is empty!"; }
else if (!preg_match("/^[a-zA-Z ]*$/",$_POST["college"])) {
$college = test($_POST["college"]);
$collegeErr = "Only letters and white space allowed"; }
else{ $college = test($_POST["college"]); }
// FB link Validation
if (empty($_POST["link"])) { $linkErr = "FB Link name is empty!"; }
else{ $link = test($_POST["link"]); }
if($nameErr==""&&$emailErr==""&&$contactErr==""&&$collegeErr==""&&$linkErr=="")
{
$conn->query("INSERT INTO ca (name, email, contact, college, link)
VALUES ('$name', '$email', '$contact' , '$college' , '$link')");
echo "Registration Successfull";
header("location:success.php");
exit;
}
}
function test($data)
{
$data=trim($data);
$data=stripcslashes($data);
$data=htmlspecialchars($data);
return $data;
}