-
Notifications
You must be signed in to change notification settings - Fork 4
/
signup_student.php
123 lines (93 loc) · 3.51 KB
/
signup_student.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
<!DOCTYPE html>
<html>
<head>
<title>Signup | BAUST Online</title>
<link href="https://fonts.googleapis.com/css?family=Work+Sans:300">
<link rel="stylesheet" type="text/css" href="css/styles.css" />
<script src="js/script.js"></script>
</head>
<?php
/**
* Created by PhpStorm.
* User: Nomaan
* Date: 02-Apr-19
* Time: 12:53 AM
*/
require_once('includes/db.php');
session_start();
if(isset($_SESSION['login_user'])){
header("location: profile.php");
}
$show_msg = "NONE";
function password_generate($chars)
{
$data = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcefghijklmnopqrstuvwxyz';
return substr(str_shuffle($data), 0, $chars);
}
if(isset($_POST['submit'])) {
$studentID = $_POST['studentID'];
$sql = "SELECT username FROM users WHERE username = '$studentID'";
if ($result = mysqli_query($db_conn, $sql)) {
if (mysqli_num_rows($result) > 0) {
$show_msg = "EXISTS";
} else {
$sql = "SELECT student_id, name, email FROM student WHERE student_id = '$studentID'";
if ($result = mysqli_query($db_conn, $sql)) {
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$student_id = $row['student_id'];
$email = $row['email'];
$password = password_generate(8);
echo "<script>alert('" . $password . "')</script>";
$sql = "INSERT INTO users (username, email, password, role) VALUES('$student_id', '$email', '$password', 3)";
$execute = mysqli_query($db_conn, $sql);
if ($execute) {
$show_msg = "SUCCESS";
} else {
$show_msg = "ERROR";
}
} else {
$show_msg = "NOTFOUND";
}
}
}
}
}
mysqli_close($db_conn);
?>
<body>
<?php $active_page = 'signup'; include('includes/header.php'); ?>
<div class="container">
<?php if($show_msg == "EXISTS"){ ?>
<div id="reg_msg_err" class="reg_message error">
<p>User already exists. Click <a href="login.php">here</a> to login </p>
</div>
<?php }?>
<?php if($show_msg == "NOTFOUND"){ ?>
<div id="reg_msg_err" class="reg_message error">
<p>Student doesn't exists in database.</p>
</div>
<?php }?>
<?php if($show_msg == "SUCCESS"){ ?>
<div id="reg_msg" class="reg_message">
<p>Registration success. Click <a href="login.php">here</a> to login </p>
</div>
<?php } else if($show_msg == "ERROR"){ ?>
<div id="reg_msg_err" class="reg_message error">
<p>Registration failed. Please try again.</p>
</div>
<?php } ?>
<div class="login-box">
<center><img src="img/avatar.png" class="avatar"></center>
<center><h1>Sign Up</h1></center>
<form name="regForm" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post" onsubmit="return validateRegForm()">
<p>Student ID</p>
<input type="text" name="studentID" placeholder="Enter Student ID" required>
<input type="submit" name="submit" value="Sign Up">
</form>
<br><center><a href="signup_teacher.php">Teacher Signup Here</a></center>
</div>
</div>
<?php include('includes/footer.php'); ?>
</body>
</html>