Prevention of Duplicate Emails Not Working Properly
Hello,
Everything works fine except for the prevention of duplicate emails. It appears that there is an error in the process-signup.php. The code was copied directly from the source provided. Perhaps, I inadvertently added or omitted a character.
ERROR RECEIVED when a duplicate email was added for a new user:
Fatal error: Uncaught mysqli_sql_exception: Duplicate entry '[email protected]' for key 'email' in C:\xampp\htdocs\php-signup-login-main\process-signup.php:45 Stack trace: #0 C:\xampp\htdocs\php-signup-login-main\process-signup.php(45): mysqli_stmt->execute() #1 {main} thrown in C:\xampp\htdocs\php-signup-login-main\process-signup.php on line 45
This is the code for http://localhost/php-signup-login-main/process-signup.php:
stmt_init(); if ( ! $stmt->prepare($sql)) { die("SQL error: " . $mysqli->error); } $stmt->bind_param("sss", $_POST["name"], $_POST["email"], $password_hash); if ($stmt->execute()) { header("Location: signup-success.html"); exit; } else { if ($mysqli->errno === 1062) { die("email already taken"); } else { die($mysqli->error . " " . $mysqli->errno); } }
Prevention of Duplicate Emails Not Working Properly #12
As stated previously, the login system works fine, except for process-signup.php. The coding does prevent a duplicate record from being created; however, the error message: "email already taken" does not print. Instead, the following error message prints when I added a new user with the same email as another user:
Fatal error: Uncaught mysqli_sql_exception: Duplicate entry '[email protected]' for key 'email' in C:\xampp\htdocs\php-signup-login-main\process-signup.php:45 Stack trace: #0 C:\xampp\htdocs\php-signup-login-main\process-signup.php(45): mysqli_stmt->execute() https://github.com/daveh/php-signup-login/issues/1 {main} thrown in C:\xampp\htdocs\php-signup-login-main\process-signup.php on line 45
This is the code for http://localhost/php-signup-login-main/process-signup.php:
The coding that I submitted for process-signup.php, in my previous comment, did not preview as I expected. Here are the actual screenshots for http://localhost/php-signup-login-main/process-signup.php:
@techangela1 Try adding this line to the top of your script:
mysqli_report(MYSQLI_REPORT_OFF);
Hello Dave,
You suggested that I put this line at the top of the script. The page is: php-signup.php
mysqli_report(MYSQLI_REPORT_OFF);
When I put it as the very first line (above the php opening tag, I got this error:
mysqli_report(MYSQLI_REPORT_OFF); Name is required
When I put it after the php opening tag, I got this error: Name is required
Any suggestions?
On Tue, Jul 25, 2023 at 4:18 AM Dave Hollingworth @.***> wrote:
@techangela1 https://github.com/techangela1 Try adding this line to the top of your script:
mysqli_report(MYSQLI_REPORT_OFF);
— Reply to this email directly, view it on GitHub https://github.com/daveh/php-signup-login/issues/12#issuecomment-1649446470, or unsubscribe https://github.com/notifications/unsubscribe-auth/BBAMKTJNMFI5FJFHOFU4JADXR6FPFANCNFSM6AAAAAA2VAW33M . You are receiving this because you were mentioned.Message ID: @.***>
@techangela1 That's the validation error you get when the form is submitted with no value for the name - try submitting the form with valid data