-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign-up.php
executable file
·126 lines (118 loc) · 3 KB
/
sign-up.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
<?php
if(isset($_POST['signup']))
{
$uname = strip_tags($_POST['txt_uname']);
$umail = strip_tags($_POST['txt_umail']);
$upass = strip_tags($_POST['txt_upass']);
if($uname=="")
{
$error[] = "Provide username !";
}
else if($umail=="")
{
$error[] = "Provide email id !";
}
else if(!filter_var($umail, FILTER_VALIDATE_EMAIL))
{
$error[] = 'Please enter a valid email address !';
}
else if($upass=="")
{
$error[] = "Provide password !";
}
else if(strlen($upass) < 6)
{
$error[] = "Password must be at least 6 characters";
}
else
{
try
{
session_start();
require_once('class.user.php');
$user = new USER();
if($user->is_loggedin()!="")
{
$user->redirect('homepage.php');
}
$stmt = $user->runQuery("SELECT user_name, user_email
FROM users
WHERE user_name=:uname OR user_email=:umail");
$stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
$row=$stmt->fetch(PDO::FETCH_ASSOC);
if($row['user_name']==$uname)
{
$error[] = "Sorry username already taken !";
}
else if($row['user_email']==$umail)
{
$error[] = "Sorry email id already taken !";
}
else
{
if($user->register($uname,$umail,$upass))
{
$user->redirect('sign-up.php?joined');
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Sign up </title>
<link rel="stylesheet" href="index.css" type="text/css" />
<style type="text/css">
</style>
</head>
<body class="normal">
<h1 class="top"></h1>
<form method="post" class="form_signin">
<div class="error">
<?php
if(isset($error))
{
foreach($error as $error)
{
?>
<?php echo $error; ?>
<?php
}
}
else if(isset($_GET['joined']))
{
?>
Successfully registered <a href='index.php' class="a">login</a> here
<?php
}
?>
</div>
<br>
<div class="required" >
Username :<br>
<input type="text" name="txt_uname" class="user_input" placeholder="Enter Username"
value="<?php if(isset($error)){echo $uname;}?>" />
</div>
<div class="required" >
E-mail :<br>
<input type="text" name="txt_umail" class="user_input" placeholder="Enter E-Mail ID"
value="<?php if(isset($error)){echo $umail;}?>" />
</div>
<div class="required" >
Password :<br>
<input type="password" name="txt_upass" class="user_input" placeholder="Enter Password" /><br>
<h2 class="hint"> (Password should be at least 6 characters) </h2>
</div>
<button type="submit" class="submit" name="signup"> SIGN UP </button>
<br><br>
Already have an account? <br><br>
<a href="index.php" class="a"> Sign In Here! </a>
</form>
</body>
</html>