-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsignup.php
More file actions
98 lines (85 loc) · 2.68 KB
/
signup.php
File metadata and controls
98 lines (85 loc) · 2.68 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
// Show all errors for debugging (remove on production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// 1. Connect to your InfinityFree DB
// $host = "sql301.infinityfree.com";
// $user = "if0_40723633";
// $pass = "Mabhelan21";
// $dbname = "if0_40723633_incubator_db";
// 1. Connect to your DB
$host = "localhost";
$user = "root";
$pass = "";
$dbname = "incubation_db";
$conn = new mysqli($host, $user, $pass, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// 2. Collect form data with basic validation
$firstname = isset($_POST['firstname']) ? trim($_POST['firstname']) : '';
$lastname = isset($_POST['lastname']) ? trim($_POST['lastname']) : '';
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
if ($firstname && $lastname && $email && $password) {
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
// 3. Insert into users table
$sql = "INSERT INTO users (firstname, lastname, email, password) VALUES (?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
if (!$stmt) {
die("Prepare failed: " . $conn->error);
}
$stmt->bind_param("ssss", $firstname, $lastname, $email, $hashedPassword);
if ($stmt->execute()) {
echo '
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
</head>
<body>
<script>
Swal.fire({
icon: "success",
title: "Registration Successful!",
text: "You will be redirected to the login page shortly...",
showConfirmButton: false,
timer: 5000,
timerProgressBar: true
});
setTimeout(() => {
window.location.href = "login.html";
}, 5000);
</script>
</body>
</html>
';
} else {
echo '
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
Swal.fire({
icon: "error",
title: "Registration Failed",
text: "' . addslashes($stmt->error) . '"
});
</script>
';
}
$stmt->close();
} else {
echo '
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
Swal.fire({
icon: "warning",
title: "Incomplete Form",
text: "Please fill in all fields."
});
</script>
';
}
$conn->close();
?>