-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_signup.php
51 lines (43 loc) · 1.51 KB
/
process_signup.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
<?php
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Database connection parameters (Replace with your own)
$db_host = "localhost";
$db_user = "admin";
$db_pass = "admin";
$db_name = "travel";
// Create a database connection
$conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Retrieve user input
$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
// You should perform input validation and sanitation here
// Hash the password (use a strong hashing algorithm)
$hashed_password = password_hash($password, PASSWORD_BCRYPT);
// Insert the user data into the database
$sql = "INSERT INTO users (user_id, password, email, first_name, last_name) VALUES (?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("sssss", $username, $hashed_password, $email, $firstname, $lastname);
if ($stmt->execute()) {
// Registration successful
echo "Registration successful!";
} else {
// Registration failed
echo "Error: " . $stmt->error;
}
// Close the database connection
$stmt->close();
$conn->close();
} else {
// Redirect to the signup page if the form is not submitted
header("Location: signup.html");
exit();
}
?>