I am trying to re-learn my web development skills for a current application project I am working on. I have verified my PHP back-end is getting the data passed to it from the HTML/JS form on the front-end. But when I submit the form the webpage does not mention any errors. Everything looks fine until I look at the database and see nothing was added. I do not see the echo at the end either that data was successfully added, or that it failed to add data.
register.php
<?php
include "conn.php";
if(empty($_POST['firstName']) || empty($_POST['lastName']) || empty($_POST['email']) || empty($_POST['password']) || empty($_POST['pin'])) {
echo "<br>Error: Please fill out all required fields.";
} else if($_POST['password'] != $_POST['confirmPassword']) {
echo "<br>Error: Passwords do not match.";
} else if($_POST['pin'] != $_POST['confirmPin']) {
echo "<br>Error: Pin codes do not match.";
} else if(strlen($_POST['password']) > 20 || strlen($_POST['password']) < 8) {
echo "<br>Error: Passwords must be between 8 and 20 characters in length.";
} else if(strlen($_POST['pin']) != 4) {
echo "<br>Error: Pin codes must be a maximum of 4 characters.";
} else if(strlen($_POST['firstName']) > 50 && strlen($_POST['lastName']) > 50 && strlen($_POST['email']) > 50) {
echo "<br>Error: First Name, Last Name, and E-mail fields must be shorter than 50 characters in length.";
} else if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
echo "<br>Error: You must use a valid e-mail address.";
} else {
echo "<br><br>Successfully checked all data!";
$options = [
'cost' => 12,
];
$hash = password_hash($_POST['password'], PASSWORD_BCRYPT, $options);
$numericPin = (int)$_POST['pin'];
$currentDateTime = date("Y-m-d H:i:s");
$stmt = $conn->prepare("INSERT INTO account (firstName, lastName, email, password, pin, registerDate) VALUES (:firstName, :lastName, :email, :password, :pin, :registerDate)");
$stmt->bindParam(":firstName", $_POST['firstName']);
$stmt->bindParam(":lastName", $_POST['lastName']);
$stmt->bindParam(":email", $_POST['email']);
$stmt->bindParam(":password", $hash);
$stmt->bindParam(":pin", $numericPin);
$stmt->bindParam(":registerdate", $currentDateTime);
if($stmt->execute()) {
echo "<br><br>Data added successfully";
} else {
echo "<br><br>Failed to add data";
}
}
?>
MySQL DB Structure: MySQL DB Structure Picture Link