-
Notifications
You must be signed in to change notification settings - Fork 0
/
s.php
117 lines (92 loc) · 2.56 KB
/
s.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
<?php
$showAlert = false;
$showError = false;
$exists=false;
if($_SERVER["REQUEST_METHOD"] == "POST") {
// Include file which makes the
// Database Connection.
include 'dbconnect.php';
$fname= $_POST["fname"];
$lname= $_POST["lname"];
$password = $_POST["password"];
$cpassword = $_POST["cfpassword"];
$email= $_POST["email"];
$phone= $_POST["phone"];
$sql = "SELECT * FROM registration WHERE email='$email'";
$result = mysqli_query($conn, $sql);
$num = mysqli_num_rows($result);
// This sql query is use to check if
// the username is already present
// or not in our Database
if($num == 0) {
if(($password == $cpassword) && $exists==false) {
//$hash = password_hash($password, PASSWORD_BCRYPT);
$hash=md5($password);
// Password Hashing is used here.
$sql = "INSERT INTO `registration` (`fname`, `lname`, `password`, `cfpassword`, `email`, `phone`)
VALUES ('$fname', '$lname', '$hash', '$hash', '$email', '$phone')";
$result = mysqli_query($conn, $sql);
if ($result) {
$showAlert = true;
}
}
else {
$showError = "Passwords do not match";
}
}// end if
if($num>0)
{
$exists="Email already in use.";
}
}//end if
?>
<?php
if($showAlert) {
header("Location:home.php");
echo "Sign Up Successful";
$_SESSION['loggedin']= true;
$_SESSION['email'] = $email;
}
if($showError) {
echo ' <div class="alert alert-danger
alert-dismissible fade show" role="alert">
<strong>Error!</strong> '. $showError.'
<button type="button" class="close"
data-dismiss="alert aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div> ';
}
if($exists) {
echo ' <div class="alert alert-danger
alert-dismissible fade show" role="alert">
<strong>Error!</strong> '. $exists.'
<button type="button" class="close"
data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div> ';
}
?>
<script>
function validation()
{
var id=document.f1.user.value;
var ps=document.f1.pass.value;
if(id.length=="" && ps.length=="") {
alert("User Name and Password fields are empty");
return false;
}
else
{
if(id.length=="") {
alert("User Name is empty");
return false;
}
if (ps.length=="") {
alert("Password field is empty");
return false;
}
}
}
</script>