-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction_page.php
More file actions
69 lines (59 loc) · 2.59 KB
/
action_page.php
File metadata and controls
69 lines (59 loc) · 2.59 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
<?php
// Start the session to store error messages
session_start();
$servername = "localhost";
$username = "root"; // Replace with your MySQL username
$password = ""; // Replace with your MySQL password
$dbname = "sanzeus_gym";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Sanitize the input
$email = htmlspecialchars($_POST['email']);
$phoneNumber = htmlspecialchars($_POST['phone_number']);
// Prepare and execute the SELECT statement to check for existing email or phone number
$stmt = $conn->prepare("SELECT * FROM registration WHERE email = ? OR phone_number = ?");
$stmt->bind_param("ss", $email, $phoneNumber);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
// Check which field is already registered
$row = $result->fetch_assoc();
if ($row['email'] == $email) {
$_SESSION['error'] = "This email is already registered.";
} else if ($row['phone_number'] == $phoneNumber) {
$_SESSION['error'] = "This phone number is already registered.";
}
// Redirect back to the form with the error message
header("Location: register.php");
exit();
} else {
// Prepare and bind the INSERT statement
$stmt = $conn->prepare("INSERT INTO registration (first_name, last_name, email, phone_number, address, dob, gender, `condition`, condition_description, attended_gym, membership_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssssiissi", $firstName, $lastName, $email, $phoneNumber, $address, $dob, $gender, $condition, $conditionDetails, $attendedGym, $membershipType);
// Set parameters and execute the INSERT statement
$firstName = htmlspecialchars($_POST['first_name']);
$lastName = htmlspecialchars($_POST['last_name']);
$address = htmlspecialchars($_POST['address']);
$dob = htmlspecialchars($_POST['dob']);
$gender = htmlspecialchars($_POST['gender']);
$condition = htmlspecialchars($_POST['condition']);
$conditionDetails = htmlspecialchars($_POST['condition_description']);
$attendedGym = htmlspecialchars($_POST['attended_gym']);
$membershipType = htmlspecialchars($_POST['membership_type']);
if ($stmt->execute()) {
$_SESSION['success'] = "New record created successfully";
} else {
$_SESSION['error'] = "Error: " . $stmt->error;
}
// Redirect back to the form with the success message
header("Location: register.php");
exit();
}
// Close statement and connection
$stmt->close();
$conn->close();
?>