-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_registration.php
59 lines (51 loc) · 1.88 KB
/
process_registration.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
52
53
54
55
56
57
58
59
<?php
require("inc/settings.php");
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Include your database connection file
include_once 'db/connection.php';
try {
// Retrieve user input
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
// Validate password match
if ($password != $confirm_password) {
die("Error: Passwords do not match.");
}
// Insert user data into the database without hashing the password
$query = "INSERT INTO users (Username, Password, Email) VALUES (?, ?, ?)";
$stmt = $dbh->prepare($query);
$stmt->bindParam(1, $username);
$stmt->bindParam(2, $password); // Store the password as plain text
$stmt->bindParam(3, $email);
if ($stmt->execute()) {
// Retrieve user data after registration
$query = "SELECT UserID, AdminLevel FROM users WHERE Username = ?";
$stmt = $dbh->prepare($query);
$stmt->bindParam(1, $username);
$stmt->execute();
$user = $stmt->fetch(PDO::FETCH_ASSOC);
// Set session variables
$_SESSION['user_id'] = $user['UserID'];
$_SESSION['admin_level'] = $user['AdminLevel'];
$_SESSION['Username'] = $username;
$_SESSION['Email'] = $email;
$url = $settings['user_dash'];
header("Location: $url");
exit;
} else {
throw new Exception("Error: " . $stmt->errorInfo()[2]);
}
} catch (Exception $e) {
// Handle exceptions (display user-friendly message or log)
echo "Registration failed: " . $e->getMessage();
} finally {
// Close the statement
if ($stmt) {
$stmt = null;
}
}
}
?>