-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
85 lines (81 loc) · 2.5 KB
/
register.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
<?php
session_start();
require_once('LoginPage/dbconfig/config.php');
//phpinfo();
?>
<!DOCTYPE html>
<html>
<head>
<title>Sign Up Page</title>
<link rel="stylesheet" href="LoginPage/css/style.css">
</head>
<body style="background-color:#bdc3c7">
<div id="main-wrapper">
<center><h2>Sign Up as A New User</h2></center>
<form action="register.php" method="post">
<div class="imgcontainer">
<img src="LoginPage/imgs/football.jpg" alt="Avatar" class="avatar">
</div>
<div class="inner_container">
<label><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="username" required>
<label><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="password" required>
<label><b>Confirm Password</b></label>
<input type="password" placeholder="Enter Password" name="cpassword" required>
<button name="register" class="sign_up_btn" type="submit">Sign Up</button>
<a href="index.php"><button type="button" class="back_btn"> Back to Login </button></a>
</div>
</form>
<?php
if(isset($_POST['register']))
{
@$username=$_POST['username'];
@$password=$_POST['password'];
@$cpassword=$_POST['cpassword'];
if($password==$cpassword)
{
$query = "select * from users where username='$username'";
//echo $query;
$query_run = mysqli_query($con,$query);
//echo mysql_num_rows($query_run);
if($query_run)
{
if(mysqli_num_rows($query_run)>0)
{
echo '<script type="text/javascript">alert("This Username Already exists.. Please try another username!")</script>';
}
else
{
$query = "insert into users values ('$username','$password')";
$query_run = mysqli_query($con,$query);
if($query_run)
{
echo '<script type="text/javascript">alert("User Registered.. Welcome")</script>';
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
header( "Location: homepage.php");
}
else
{
echo '<p class="bg-danger msg-block">Registration Unsuccessful due to server error. Please try later</p>';
}
}
}
else
{
echo '<script type="text/javascript">alert("DB error")</script>';
}
}
else
{
echo '<script type="text/javascript">alert("Password and Confirm Password do not match")</script>';
}
}
else
{
}
?>
</div>
</body>
</html>