-
Notifications
You must be signed in to change notification settings - Fork 0
/
registration.php
65 lines (52 loc) · 1.87 KB
/
registration.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
<?php
// Include config file
require_once "config2.php";
// Define variables and initialize with empty values
$username = $email = $password = "";
$username_err = $email_err = $password_err = "";
// Processing form data when form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Validate username
if (empty(trim($_POST["username"]))) {
$username_err = "Please enter a username.";
} else {
$username = trim($_POST["username"]);
}
// Validate email
if (empty(trim($_POST["email"]))) {
$email_err = "Please enter an email.";
} else {
$email = trim($_POST["email"]);
}
// Validate password
if (empty(trim($_POST["password"]))) {
$password_err = "Please enter a password.";
} else {
$password = trim($_POST["password"]);
}
// Check input errors before inserting into database
if (empty($username_err) && empty($email_err) && empty($password_err)) {
// Prepare an INSERT statement
$sql = "INSERT INTO users1 (username, email, password) VALUES (?, ?, ?)";
if ($stmt = $conn->prepare($sql)) {
// Bind variables to the prepared statement as parameters
$stmt->bind_param("sss", $param_username, $param_email, $param_password);
// Set parameters
$param_username = $username;
$param_email = $email;
$param_password = $password;
// Attempt to execute the prepared statement
if ($stmt->execute()) {
//Redirect to login page
header("location: login.html");
} else {
echo "Something went wrong. Please try again later.";
}
// Close statement
$stmt->close();
}
}
// Close connection
$conn->close();
}
?>