-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
80 lines (64 loc) · 2.59 KB
/
Copy pathindex.php
File metadata and controls
80 lines (64 loc) · 2.59 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
session_start();
include("database.php");
$message = "";
// Handle form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = trim(filter_input(INPUT_POST, "username", FILTER_SANITIZE_SPECIAL_CHARS));
$password = trim(filter_input(INPUT_POST, "password", FILTER_SANITIZE_SPECIAL_CHARS));
if (empty($username)) {
$_SESSION["message"] = "Please enter a username.";
} elseif (empty($password)) {
$_SESSION["message"] = "Please enter a password.";
} else {
$hash = password_hash($password, PASSWORD_DEFAULT);
$stmt = mysqli_prepare($conn, "INSERT INTO users (user, password) VALUES (?, ?)");
mysqli_stmt_bind_param($stmt, "ss", $username, $hash);
if (mysqli_stmt_execute($stmt)) {
$_SESSION["message"] = "You are now registered! <br> Thank you for testing this registration form :)";
} else {
if (mysqli_errno($conn) == 1062) {
$_SESSION["message"] = "Username already taken. Please try again.";
} else {
$_SESSION["message"] = "Error: " . mysqli_error($conn);
}
}
mysqli_stmt_close($stmt);
}
mysqli_close($conn);
header("Location: " . $_SERVER["PHP_SELF"]);
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Movieboxd</title>
<link rel="icon" type="image/x-icon" href="movielogo.ico">
<link rel="stylesheet" href="styles.css">
<link href="https://fonts.googleapis.com/css2?family=Mulish&display=swap" rel="stylesheet">
</head>
<body>
<img src="moviesbg.png" class="background-png" alt="Background">
<div class="form">
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<img src="movieboxd.png" class="sitelogo" alt="Movieboxd" />
<h2>Welcome to Movieboxd!</h2>
<label>Username:</label>
<input type="text" name="username" required>
<label>Password:</label>
<input type="password" name="password" required>
<div class="button-container">
<input type="submit" value="Register">
</div>
<br>
<?php if (isset($_SESSION["message"])): ?>
<div class="form-message"><?php echo $_SESSION["message"]; ?></div>
<?php unset($_SESSION["message"]); ?>
<?php endif; ?>
</form>
</div>
</body>
</html>