This repository has been archived by the owner on Dec 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
157 lines (150 loc) · 3.92 KB
/
signup.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
session_start(); // start the session
validateForm();
?>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="description" content="Web application development" />
<meta name="keywords" content="PHP" />
<meta name="author" content="David Sam" />
<title>Sign-Up</title>
</head>
<body>
<center>
<h2>My Friend System</h2>
<h2>Registration Page</h2>
</center>
</br>
<span style="text-align:center">
<style>
</style>
<form action="" method="POST">
<p>Email: <input type="email" name="email" value="<?php echo isset($semail)?$semail:"";?>" required />
</p>
<p>Profile Name: <input type="text" name="pname" value="<?php echo isset($sname)?$sname:"";?>" required title="- Letter only." pattern="[A-Za-z]+" />
</p>
<p>Password: <input type="password" name="pwd" required title="- Only number and letter allowed." pattern="[A-Za-z0-9]+" />
</p>
<p>Confirm Password: <input type="password" name="cpwd" required />
</p>
<span style="padding-right: 40px;">
<input type="submit" value="Register"/>
</span>
<input type="reset" value="Clear"/>
</form>
</br>
</span>
<div style="text-align:center">
<a href="index.php"> Home </a>
</div>
</body>
</html>
<?php
function checkPwd() // check if both password matched
{
$result = true;
if(isset($_POST["pwd"]) && isset($_POST["cpwd"]))
{
$pwd = $_POST["pwd"];
$cpwd = $_POST["cpwd"];
if(strcmp($pwd,$cpwd))
{
$result = false;
}
}
return $result;
}
?>
<?php
function checkEmail($search,$conn) // check if email is already registered
{
$SQLstring = "SELECT * FROM friends where friend_email='$search'";
$QueryResult = @mysqli_query($conn, $SQLstring);
if (mysqli_num_rows($QueryResult)==0) { //if search not found return true = your email is not in records and you good to go;
return true;
}else
return false;
}
?>
<?php
function getConnection()
{
require_once ("settings.php");
$DBConnect = @mysqli_connect($host, $user, $pswd,$dbnm)
Or die("<p>Unable to connect to the database server.</p>"
. "<p>Error code " . mysqli_connect_errno()
. ": " . mysqli_connect_error()) . "</p>";
return $DBConnect;
}
?>
<?php
function redirect() // when done signed up
{
$_SESSION["signup"] = true;
header("location:friendadd.php");
}
?>
<?php
function getInfo($search,$conn) // function to get info of search and store in session
{
$SQLstring = "SELECT * FROM friends where friend_email='$search'";
$QueryResult = @mysqli_query($conn, $SQLstring);
while($rows = mysqli_fetch_assoc($QueryResult))
{
$_SESSION["info"] = $rows;
}
}
?>
<?php
function validateForm() // validate
{
global $semail;
global $sname;
$conn = getConnection();
$errs = array();
if(isset($_POST["email"]) && isset($_POST["pname"]) && isset($_POST["pwd"]) && isset($_POST["cpwd"]))
{
if(checkEmail($_POST["email"],$conn))
{
$emailcheck = true;
}else
{
$emailcheck = false;
array_push($errs,"<p>". $_POST["email"] . " already exist. Try different email.</p>");
}
if(checkPwd()) // if not matched
{
$passcheck = true;
}else
{
$passcheck = false;
array_push($errs,"<p> Password do not match. Try again.</p>");
}
if($passcheck && $emailcheck)
{
$email = $_POST["email"];
$pwd = $_POST["pwd"];
$pname = $_POST["pname"];
$date = date("Y-m-d");
$SQLstring = "insert into friends(friend_email,password,profile_name,date_started,num_of_friends) Values ('$email','$pwd','$pname','$date',0)";
$QueryResult = @mysqli_query($conn, $SQLstring);
getInfo($email,$conn);
redirect(); // when everything is success
}else
{
$semail = $_POST["email"];
$sname = $_POST["pname"];
$_SESSION["name"] = $sname;
$_SESSION["email"] = $semail;
if(!empty($errs))
{
foreach($errs as &$err)
{
echo $err;
}
}
}
}
}
?>