-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistration_process.php
More file actions
61 lines (53 loc) 路 2.04 KB
/
Copy pathregistration_process.php
File metadata and controls
61 lines (53 loc) 路 2.04 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
<?php
session_start();
require_once('db_config.php');
if (isset($_POST['signup'])) {
$fullName = $_POST['name'];
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$confirmPassword = $_POST['confirm_password'];
if (empty($fullName) || empty($username) || empty($email) || empty($password) || empty($confirmPassword)) {
header("Location: index.php?error_signup=Please fill in all fields");
exit();
}
if ($password !== $confirmPassword) {
header("Location: index.php?error_signup=Passwords do not match");
exit();
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: index.php?error_signup=Invalid email format");
exit();
}
try {
$stmt = $pdo->prepare("SELECT COUNT(*) FROM users WHERE username = :username");
$stmt->execute(['username' => $username]);
if ($stmt->fetchColumn() > 0) {
header("Location: index.php?error_signup=Username already exists");
exit();
}
$stmt = $pdo->prepare("SELECT COUNT(*) FROM users WHERE email = :email");
$stmt->execute(['email' => $email]);
if ($stmt->fetchColumn() > 0) {
header("Location: index.php?error_signup=Email already exists");
exit();
}
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (full_name, username, email, password) VALUES (:full_name, :username, :email, :password)");
$stmt->execute([
'full_name' => $fullName,
'username' => $username,
'email' => $email,
'password' => $hashedPassword
]);
header("Location: index.php?success=Registration successful! Please login.");
exit();
} catch(PDOException $e) {
header("Location: index.php?error_signup=Database error. Please try again later.");
exit();
}
} else {
header("Location: index.php");
exit();
}
?>