2024-01-20 16:04:27 +01:00
|
|
|
<?php
|
|
|
|
session_start();
|
|
|
|
require_once 'config.php';
|
|
|
|
|
|
|
|
// Handle registration form submission
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
|
|
$username = $_POST['username'];
|
|
|
|
$email = $_POST['email'];
|
|
|
|
$password = $_POST['password'];
|
|
|
|
|
|
|
|
// Hash the password
|
|
|
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
|
|
|
|
2024-01-20 16:35:03 +01:00
|
|
|
// Prepare and execute the SQL query using prepared statements
|
|
|
|
$query = "INSERT INTO users (username, email, password) VALUES (?, ?, ?)";
|
|
|
|
$stmt = $mysqli->prepare($query);
|
|
|
|
$stmt->bind_param("sss", $username, $email, $hashed_password);
|
|
|
|
|
|
|
|
// Execute the statement
|
|
|
|
$result = $stmt->execute();
|
2024-01-20 16:04:27 +01:00
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
echo "Registration successful. <a href='login.html'>Login here</a>.";
|
|
|
|
} else {
|
2024-01-20 16:35:03 +01:00
|
|
|
echo "Error: " . $mysqli->error;
|
2024-01-20 16:04:27 +01:00
|
|
|
}
|
2024-01-20 16:35:03 +01:00
|
|
|
|
|
|
|
// Close the statement
|
|
|
|
$stmt->close();
|
2024-01-20 16:04:27 +01:00
|
|
|
}
|
|
|
|
?>
|