-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsignup.php
More file actions
57 lines (44 loc) · 1.68 KB
/
Copy pathsignup.php
File metadata and controls
57 lines (44 loc) · 1.68 KB
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
<?php
include_once('config.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS);
$pass = filter_input(INPUT_POST, 'pass', FILTER_SANITIZE_SPECIAL_CHARS);
$pass1 = password_hash($pass, PASSWORD_DEFAULT);
$repass = filter_input(INPUT_POST, 'repass', FILTER_SANITIZE_SPECIAL_CHARS);
if ($repass != $pass) {
?>
<script>alert("password not match");</script>
<?php
} else {
// $hashed = passzword_hash($pass, PASSWORD_DEFAULT);
// Check if the username is already registered
$check = "SELECT * FROM registration WHERE username ='$username'";
$query = mysqli_query($conn, $check);
if (mysqli_num_rows($query) > 0) {
?>
<script>alert("Already Registered");
window.location="log-in.php";
</script>
<?php
} else {
// Insert new user into the database
$sql = "INSERT INTO registration(username, password) VALUES ('$username', '$pass1')";
try {
$query = mysqli_query($conn, $sql);
if ($query) {
?>
<script>
alert("Registration Done");
window.location="log-in.php";
</script>
<?php
}
} catch (mysqli_sql_exception $e) {
?>
<script>alert("Something went wrong: <?php echo $e->getMessage(); ?>");</script>
<?php
}
}
}
}
?>