-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
115 lines (96 loc) · 2.77 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
<?php
$error=null;
include 'database.php';
if($_SERVER["REQUEST_METHOD"]=="POST")
{
$name=$_POST['name'];
$user=$_POST['uname'];
$email=$_POST['email'];
$password=$_POST['psw'];
try
{
//$result=mysql_query("SELECT * from users");
$result1=$db->prepare("SELECT * from users where username=?");
$result1->bindParam(1,$user);
$result1->execute();
$result2=$db->prepare("SELECT * from users where email=?");
$result2->bindParam(1,$email);
$result2->execute();
}
catch(exception $e)
{
$error= "OOPS! data cannot be fetched from Database";
}
$result1=$result1->fetch(PDO::FETCH_ASSOC);
$result2=$result2->fetch(PDO::FETCH_ASSOC);
include("phpmailer/class.smtp.php");
require_once 'phpmailer/PHPMailerAutoload.php';
$mail=new PHPMailer;
if(!$mail->ValidateAddress($email))
{
$error= "Please enter your valid mail address";
}
else if($result1 === FALSE && $result2 === FALSE)
{
try
{
$result=$db->prepare("insert into users value(?,?,?,?)");
$result->bindParam(1,$name);
$result->bindParam(2,$user);
$result->bindParam(3,$email);
$result->bindParam(4,$password);
if($result->execute())
{
?>
<script>
location.replace("login.php");
</script><?php
}
}
catch(exception $e)
{
echo "OOPS! data cannot be fetched from Database";
}
// TODO: better error handling
}
else if($result2 === FALSE)
{
$error= "Username already exist.Please try another one.";
}
else if($result1 === FALSE)
{
$error= "Email already registered.Please try another one.";
}
}
?>
<?php
$header = "Sign Up";
include('header.php');
?>
<html>
<?php $message="Welcome.. Please fill details and submit to get registered."?>
<div class="imgcontainer">
<img src="login.png" alt="Avatar" class="avatar">
</div>
<p class="text-center"><?php
if($error == null) echo $message;
else{ ?><h4 class="error text-center"><?php echo $error;}?>
</h4></p>
<form action="" method="post">
<div class="container">
<label for="name"><b>Name</b></label>
<input type="text" name="name" required>
<label for="uname"><b>Username</b></label>
<input type="text" name="uname" required>
<label for="email"><b>Email</b></label>
<input type="text" name="email" required>
<label for="psw"><b>Password</b></label>
<input type="password" name="psw" required>
<button type="submit">Sign Up</button>
</div>
<div class="container" style="background-color:#f1f1f1">
<span class=""><a href="login.php">Login</a></span>
</div>
</form>
</html>
<?php include('footer.php');?>