-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit-signup.php
50 lines (41 loc) · 1.41 KB
/
submit-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
<?php
// Database configuration
$servername = "localhost"; // Update if your server is different
$username = "root"; // Update with your database username
$password = ""; // No password for the database
$dbname = "6th"; // Use the database name '6th'
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Collect and sanitize form data
$fullName = htmlspecialchars(trim($_POST['fullName']));
$email = htmlspecialchars(trim($_POST['email']));
$password = htmlspecialchars(trim($_POST['password']));
$confirmPassword = htmlspecialchars(trim($_POST['confirmPassword']));
// Basic validation
if (empty($fullName) || empty($email) || empty($password) || empty($confirmPassword)) {
echo "All fields are required.";
exit;
}
if ($password !== $confirmPassword) {
echo "Passwords do not match.";
exit;
}
// Hash the password
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
// Prepare and bind
$stmt = $conn->prepare("INSERT INTO users (full_name, email, password) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $fullName, $email, $hashedPassword);
// Execute the statement
if ($stmt->execute()) {
echo "Sign up successful!";
} else {
echo "Error: " . $stmt->error;
}
// Close connections
$stmt->close();
$conn->close();
?>