-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
93 lines (83 loc) · 3.42 KB
/
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
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
<?php
// Enable error reporting for debugging
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Connect to the database
$db = new SQLite3('admin_users.db');
// Handle form submission for account creation
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$phone = htmlspecialchars($_POST['phone']);
// Insert the user into the database
$insertQuery = "INSERT INTO users (name, email, password, phone) VALUES (:name, :email, :password, :phone)";
$stmt = $db->prepare($insertQuery);
$stmt->bindValue(':name', $name, SQLITE3_TEXT);
$stmt->bindValue(':email', $email, SQLITE3_TEXT);
$stmt->bindValue(':password', $password, SQLITE3_TEXT);
$stmt->bindValue(':phone', $phone, SQLITE3_TEXT);
if ($stmt->execute()) {
$success = true;
} else {
$error = "This email is already registered.";
}
}
// Fetch visible roles from the database
$rolesQuery = "SELECT id, role_name FROM volunteer_roles WHERE visible = 1";
$rolesResult = $db->query($rolesQuery);
$roles = [];
while ($row = $rolesResult->fetchArray(SQLITE3_ASSOC)) {
$roles[] = $row;
}
// Close the database connection
$db->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Volunteer Signup</title>
</head>
<body class="bg-light">
<div class="container py-5">
<h1 class="text-center mb-4">Volunteer Signup</h1>
<?php if (!empty($success)): ?>
<div class="alert alert-success">Account created successfully! You can now choose your role below.</div>
<?php elseif (!empty($error)): ?>
<div class="alert alert-danger"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<form method="POST" action="" class="mb-5">
<h3>Create Your Account</h3>
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="mb-3">
<label for="phone" class="form-label">Phone (Optional)</label>
<input type="text" class="form-control" id="phone" name="phone">
</div>
<button type="submit" class="btn btn-primary">Create Account</button>
</form>
<h3>Choose Your Role</h3>
<div class="list-group">
<?php foreach ($roles as $role): ?>
<a href="role_signup.php?role_id=<?= $role['id'] ?>" class="list-group-item list-group-item-action">
<?= htmlspecialchars($role['role_name']) ?>
</a>
<?php endforeach; ?>
</div>
</div>
</body>
</html>