Changes in html and Login/Register php

This commit is contained in:
2024-01-20 16:35:03 +01:00
parent 4c43261455
commit a7c943676f
5 changed files with 84 additions and 12 deletions

View File

@@ -11,14 +11,21 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Hash the password
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// Insert user into the database
$query = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$hashed_password')";
$result = mysqli_query($mysqli, $query);
// 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();
if ($result) {
echo "Registration successful. <a href='login.html'>Login here</a>.";
} else {
echo "Error: " . mysqli_error($mysqli);
echo "Error: " . $mysqli->error;
}
// Close the statement
$stmt->close();
}
?>