-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthor-signup-action.php
47 lines (38 loc) · 1.43 KB
/
author-signup-action.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
<?php
session_start(); // Start the session
require 'utilities/db.php'; // Ensure this file sets up the $conn variable for the database connection
// Collect form data
$firstName = $_POST['fname'];
$lastName = $_POST['lname'];
$email = $_POST['email'];
$password = $_POST['psw'];
// Hash the password
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
// Prepare SQL statement to insert a new author record
$sql = "INSERT INTO Author (first_name, last_name, email, password) VALUES (?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
// Check if the statement was prepared successfully
if ($stmt === false) {
die("Error preparing the statement: " . $conn->error);
}
// Bind the parameters to the SQL statement
$stmt->bind_param("ssss", $firstName, $lastName, $email, $hashedPassword);
// Execute the query
$result = $stmt->execute();
// Check if the insertion was successful
if ($result) {
// Redirect the user to the login page with a success message
header("Location: home.php?signup_success=1");
exit();
} else {
// Handle duplicate email error
if ($stmt->errno == 1062) {
echo "Error: The email you entered is already registered.";
} else {
echo "Error adding author: " . $stmt->error;
}
}
// Close statement and connection
$stmt->close();
$conn->close();
?>