-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
88 lines (73 loc) · 3.04 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
<?php
require_once('db-connect.php');
session_start();
?>
<html lang="en de tr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<title>Sign Up</title>
</head>
<body class="bg-light">
<div class="d-flex align-items-center justify-content-center p-4"></div>
<div class="container d-flex align-items-center justify-content-center">
<div class="card bg-light" style="width: 18rem;">
<div class="card-header bg-primary"> Sign up </div>
<div class="card-body">
<!-- ERROR -->
<?php if($_SESSION['error']): ?>
<div class="alert alert-danger"> <?= $_SESSION['error'] ?> </div>
<?php endif; ?>
<!-- SIGN UP -->
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<label for="username" class="text-success">User Name</label>
<input type="text" name="username" value="" class="form-control" required>
<label for="password" class="text-success">Password</label>
<input type="text" name="password" value="" class="form-control" required>
<label for="email" class="text-success">E-mail</label>
<input type="email" name="email" value="" class="form-control" required>
<button class="btn btn-primary mt-4 mb-2 w-100">Sign Up</button>
</form>
<center>or</center>
<!-- LOGIN -->
<form action="login.php">
<button class="btn btn-secondary mt-4 mb-2 w-100">Back to Login</button>
</form>
</div>
</div>
</div>
<?php
echo "<pre>";
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$_SESSION['username'] = $_POST['username'];
$_SESSION['email'] = $_POST['email'];
$_SESSION['password'] = $_POST['password'];
$users = $conn->query("SELECT * FROM `user_list`");
foreach ($users->fetch_all(MYSQLI_ASSOC) as $user){
if($_SESSION['username'] == $user['username'] || $_SESSION['email'] == $user['email']){
$_SESSION['error'] = "The username or Email is already registered!";
echo "<script> alert('$_SESSION[error]'); location.replace('./') </script>";
}
}
$sql = "INSERT INTO `user_list` (`username`,`email`,`password`) VALUES ('$_POST[username]','$_SESSION[email]','$_SESSION[password]')";
$save = $conn->query($sql);
if($save) echo "<script> alert('You have been successfully registered!'); location.replace('./') </script>";
else{ // Error - DB Connection
echo "<pre>";
echo "An Error occured.<br>";
echo "Error: ".$conn->error."<br>";
echo "SQL: ".$sql."<br>";
echo "</pre>";
}
}
// Delete data by the end of session
// $_SESSION['username'] = null;
// $_SESSION['password'] = null;
// $_SESSION['email'] = null;
// $_SESSION['error'] = null;
// session_destroy();
?>
</body>
</html>