-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess.php
46 lines (41 loc) · 1.4 KB
/
process.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
<?php
require 'DatabaseConnection.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get form data
$email = $_POST['email'];
$password = $_POST['password'];
$firstName = $_POST['firstname'];
$lastName = $_POST['lastname'];
$address = $_POST['address'];
$phone = $_POST['phoneNumber'];
// Validate inputs
if (empty($email) || empty($password) || empty($firstName) || empty($lastName) || empty($address) || empty($phone)) {
echo "All fields are required.";
exit;
}
// Create a new instance of the Database class
$db = new Database();
// Insert user into the database
$sql = "INSERT INTO tblstudent (email, password, firstName, lastName, address, phoneNumber) VALUES (:email, :password, :firstName, :lastName, :address, :phoneNumber)";
$params = [
':email' => $email,
':password' => $password,
':firstName' => $firstName,
':lastName' => $lastName,
':address' => $address,
':phoneNumber' => $phone
];
try {
$rowCount = $db->executeQuery($sql, $params);
if ($rowCount > 0) {
require 'header.php';
echo "Registration successful!";
} else {
require 'header.php';
echo "Failed to register.";
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
}
?>