-
Notifications
You must be signed in to change notification settings - Fork 0
/
registration.php
46 lines (36 loc) Β· 1.09 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
<?php
// Function to safely get post values
function getPostValue($key) {
return filter_input(INPUT_POST, $key, FILTER_SANITIZE_STRING);
}
$username = getPostValue('username');
$email = getPostValue('email');
$password = getPostValue('password');
// Check if any field is empty
if (empty($username) || empty($email) || empty($password)) {
echo "All fields are required.";
die();
}
// Database connection details
$host = "localhost";
$dbUsername = "root";
$dbPassword = "root";
$dbname = "login";
// Create connection
$conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Prepare and execute SQL query
$sql = "INSERT INTO register (username, email, password) VALUES ('$username', '$email', '$password')";
if ($conn->query($sql)) {
// Registration successful, redirect to home.html
header("location: home.html");
} else {
// Registration failed, redirect to login and Register.html
header("location: login and Register.html");
}
// Close connection
$conn->close();
?>