This repository has been archived by the owner on Oct 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
109 lines (99 loc) · 6.59 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
<?php
include_once "views/partials/header.html";
require('config.php');
?>
<body>
<section>
<div class="container-fluid bg-slider">
<div class="row">
<div class="col-md-4 frost">
<div class="toplayer login-card-body">
<img class="img-fluid mx-auto d-block" src="assets/img/IRIMSLOGO.png" width="95" height="95">
<div class="pt-0 pe-5 pb-5 ps-5">
<form class="form" method="post" id="signup-form">
<div class="mt-4">
<div class="row mb-2">
<div class="col-md-6"><label class="form-label col-sm-12 col-form-label rxpress-color fs-5" for="first-name">First Name</label><input class="form-control border-form rounded-pill" type="text" id="first-name" name="firstname" required></div>
<div class="col-md-6"><label class="form-label col-sm-12 col-form-label rxpress-color fs-5" for="last-name">Last Name</label><input class="form-control border-form rounded-pill" type="text" id="last-name" name="lastname" required></div>
</div>
</div>
<div class="col mb-2"><label class="form-label col-sm-12 col-form-label rxpress-color fs-5" for="username">Username</label><input class="form-control border-form rounded-pill" type="text" id="username" name="username" required></div>
<div class="col mb-2"><label class="form-label col-sm-12 col-form-label rxpress-color fs-5" for="contact">Contact Number</label><input class="form-control border-form rounded-pill" type="number" id="contact" name="contact" required></div>
<div class="form-group">
<label class="form-label col-sm-12 col-form-label rxpress-color fs-5" for="department">Department</label>
<select class="form-select rounded-pill" name="department" id="department">
<option value="" disabled selected></option>
<?php
$sql = "SELECT * FROM department WHERE DepartmentID > 0";
$result = $con->query($sql) or die(mysql_error());
while ($row = $result->fetch_assoc()) { ?>
<option value="<?php echo $row['DepartmentID'] ?>"><?php echo $row['DepartmentName'] ?></option>
<?php }
?>
</select>
</div>
<div class="col mb-2"><label class="form-label col-sm-12 col-form-label rxpress-color fs-5" for="password">Password</label><input class="form-control border-form rounded-pill" type="password" id="password" name="password" required onChange="onChange()"></div>
<div class="col mb-5"><label class="form-label col-sm-12 col-form-label rxpress-color fs-5" for="confirm">Confirm Password</label><input class="form-control border-form rounded-pill" type="password" id="confirm" name="confirm" required onChange="onChange()"></div>
<div class="col mb-2"><button class="col-12 btn btn-color rounded-pill fs-5" name="submit" id="signup" type="submit">SIGN UP</button></div>
<div class="col text-center mb-5"><a class="text-dark text-decoration-none" href="index.php">ALREADY HAVE AN ACCOUNT? LOGIN</a></div>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
<script>
function onChange() {
const password = document.querySelector('#password');
const confirm = document.querySelector('#confirm');
if (password.value != confirm.value) {
confirm.setCustomValidity('Passwords do not match');
} else {
confirm.setCustomValidity('');
}
}
function successAlert() {
Swal.fire({
title: "Registered Successfully!",
text: "You have successfully created an account. Go to the login page",
confirmButtonColor: "#00A3A8",
icon: "success",
}).then((result) => {
if (result['isConfirmed']) {
window.location.href = "/irims";
}
})
}
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/gh/alumuko/vanilla-datetimerange-picker@latest/dist/vanilla-datetimerange-picker.js"></script>
<script src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<?php
// When form submitted, insert values into the database.
if (isset($_REQUEST['username'])) {
// removes backslashes
$username = stripslashes($_REQUEST['username']);
//escapes special characters in a string
$username = mysqli_real_escape_string($con, $username);
$firstname = stripslashes($_REQUEST['firstname']);
$firstname = mysqli_real_escape_string($con, $firstname);
$lastname = stripslashes($_REQUEST['lastname']);
$lastname = mysqli_real_escape_string($con, $lastname);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con, $password);
$contact = stripslashes($_REQUEST['contact']);
$contact = mysqli_real_escape_string($con, $contact);
$deptID = $_REQUEST['department'];
mysqli_query($con, "ALTER TABLE user AUTO_INCREMENT=1;") or die(mysql_error());
$query = "INSERT INTO `user` (`UserID`, `Username`, `FirstName`, `LastName`, `UserPassword`, `DepartmentID`, `ContactNO`, `IsAdmin`) VALUES (NULL, '$username', '$firstname', '$lastname', '$password', '$deptID', '$contact', b'0') ";
$result = mysqli_query($con, $query) or die(mysql_error());
if ($result) {
echo "<script>successAlert()</script>";
}
}
?>
</body>
</html>