Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Uncaught mysqli_sql_exception: Duplicate entry '[email protected]' for key 'email' #5

Closed
Th0ngpv opened this issue Nov 3, 2022 · 3 comments

Comments

@Th0ngpv
Copy link

Th0ngpv commented Nov 3, 2022

Fatal error: Uncaught mysqli_sql_exception: Duplicate entry '[email protected]' for key 'email' in C:\xampp\htdocs\php-signup-login\process-signup.php:45 Stack trace: #0 C:\xampp\htdocs\php-signup-login\process-signup.php(45): mysqli_stmt->execute() #1 {main} thrown in C:\xampp\htdocs\php-signup-login\process-signup.php on line 45

I keep getting this error and don't know what to do .

@Th0ngpv Th0ngpv closed this as completed Nov 3, 2022
@Th0ngpv Th0ngpv changed the title Fatal error: Uncaught mysqli_sql_exception: Duplicate entry 'name' for key 'name' Fatal error: Uncaught mysqli_sql_exception: Duplicate entry '[email protected]' for key 'email' Nov 3, 2022
@Th0ngpv Th0ngpv reopened this Nov 3, 2022
@daveh
Copy link
Owner

daveh commented Nov 3, 2022

If you have a unique index on the email column, you'll get this error if you try and insert a new value - what code do you have for catching the duplicate index error?

@poetaetoh
Copy link

Try this. Instead of for example

if ($stmt->execute()) {

    header("Location: signup-success.html");
    exit;
    
} else {
    
    if ($mysqli->errno === 1062) {
        die("email already taken");
    } else {
        die($mysqli->error . " " . $mysqli->errno);
    }
}

Change the structure into something like

try
    {
      $stmt->execute();
      header("Location: signup-success.html");
      exit;
    }
catch(Throwable $e)
    {
      echo $e;
      if ($mysqli->errno === 1062) {
        echo "email already taken";
          } else {
              echo "$mysqli->error $mysqli->errno";
          }
    }

Hope it helps.

@Th0ngpv
Copy link
Author

Th0ngpv commented Nov 6, 2022

add this line of code before check for email

mysqli_report(MYSQLI_REPORT_OFF);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants