My code worked perfectly when hosted locally for testing but stopped inserting data into database after I hosted the website online. Other parts of the website that insert into database are working fine except the signup for client. The sign up for admins/operators is also working fine. I've been trying to solve this issue for a while now but to no avail. And also after inserting data into database manually, I can login and also update the profile. Before I forget, after filling the form and submitting you get the success message.
<?php
if (isset($_POST['signup'])) {
$f_name = trim($_POST['Fname']);
$l_name = trim($_POST['Lname']);
$client_name = $f_name ." ". $l_name;
$client_phone = trim($_POST['phone']);
$sec_question = trim($_POST['sec-question']);
$sec_answer = trim($_POST['sec-answer']);
$client_email = trim($_POST['email']);
$sql = "SELECT * FROM clients WHERE client_email = :email";
$stmt = $pdo->prepare($sql);
$stmt->execute([
':email' => $client_email
]);
$countEmail = $stmt->rowCount();
if($countEmail != 0) {
$error_email_exist = "Email already taken!";
}
$client_password = trim($_POST['password']);
$confirm_password = trim($_POST['confirmPassword']);
if($client_password != $confirm_password) {
$error = "Please check your password";
}else {
$hash_pass = password_hash($client_password, PASSWORD_BCRYPT, ['cost'=>10]);
$sql1 = "INSERT INTO clients (client_name, client_email, client_password, client_phone, sec_question, sec_answer) VALUES (:name, :email, :password, :phone, :sec_q, :sec_a)";
$stmt = $pdo->prepare($sql1);
$stmt->execute([
':name' => $client_name,
':email' => $client_email,
':password' => $hash_pass,
':phone' => $client_phone,
':sec_q' => $sec_question,
':sec_a' => $sec_answer
]);
$success = true;
}
}
?>
<div class="col-sm-8 col-12">
<form action="client-signup.php" method="post">
<div class="row mt-3">
<div class="col-12 mb-2">
<h4><strong>SIGN UP</strong></h4>
</div>
<hr class="d-block d-sm-block">
<div class="col-12">
<?php
if(isset($error_email_exist)) {
echo "<p class='alert alert-danger'>{$error_email_exist}</p>";
}elseif (isset($error)) {
echo "<p class='alert alert-danger'>{$error}</p>";
}elseif (isset($success)) {
echo "<p class='alert alert-success'>Great! Signup Successful. <a href='client-signin.php'>Sign in now</a>.</p>";
}
?>
</div>
<div class="col-12">
<h5><strong>Name</strong></h5>
</div>
<div class="col-12 input-group mb-4">
<input type="text" name="Fname" class="form-control" placeholder="First Names *" required />
<input type="text" name="Lname" class="form-control" placeholder="Last Name *" required />
</div>
<div class="col-12">
<h5><strong>Password</strong></h5>
</div>
<div class="col-12 input-group mb-3">
<input type="password" name="password" class="form-control" placeholder="Create New Password *" required />
<input type="password" name="confirmPassword" class="form-control" placeholder="Confirm Password *" required />
</div>
<div class="col-12 col-sm-2 mt-sm-3">
<h5><strong>Email</strong></h5>
</div>
<div class="col-12 col-sm-10 mt-sm-3">
<input type="email" name="email" class="form-control" placeholder="Enter Email Address *" required />
</div>
<div class="col-12 col-sm-2 mt-sm-3 mt-3">
<h5><strong>Phone</strong></h5>
</div>
<div class="col-12 col-sm-10 mt-sm-3">
<input type="phone" name="phone" class="form-control col-sm-6" placeholder="Enter Phone Number *" required />
</div>
<div class="col mt-2">
<hr>
</div>
<div class="col-12 mt-sm-3 mt-3">
<h5><strong>Security (For Password Reset)</strong></h5>
</div>
<div class="col-12 mt-sm-1">
<select name="sec-question" id="security" class="form-control">
<option value="#">Choose a security question</option>
<option value="What is your pet's name?">What is your pet's name?</option>
<option value="Which year did you meet your spouse?">Which year did you meet your spouse?</option>
<option value="What is your favourite fruit?">What is your favourite fruit?</option>
<option value="At what age did you cook your first meal?">At what age did you cook your first meal?</option>
</select>
</div>
<div class="col-12 mt-sm-3 mt-1">
<input type="text" name="sec-answer" class="form-control col-sm-6" placeholder="Answer to question *" required />
</div>
<div class="col mt-2">
<hr>
</div>
<div class="col-12">
<input type="checkbox" checked name="TnC" id="Terms" class="checkbox" required /> <span for="Terms"> I accept all <a href="#offcanvasTnC" data-bs-toggle="offcanvas" role="button" aria-controls="offcanvasTnC" class="black-link"><u>Terms and Conditions</u></a> of Bulky Africa.</span>
</div>
</div>
<div class="row">
<div class="col mt-4">
<button type="submit" name="signup" class="col-12 btn btn-lg btn-primary">SIGN UP</button>