• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Handle error for duplicate entries - PHP/MySQL

phpmysqlerror-handlingtry-catch


PHP Snippet 1:

catch (PDOException $e) {

  if(str_contains($e, '1062 Duplicate entry')) {
      header("Location: login.php");

  }
      die("Error inserting user details into database: " .  $e->getMessage());

}

Related Snippets

Installing Composer - Internal Error

Using Associative arrays

Malformed MIME header error in Symfony 5.3

Access relation of pivot table in Laravel

Laravel s3 upload file with metadata using pre-signed url

How to send parameters in soap request in php in __soapcall() function

SQL AVG() to 2 decimals

What will the best solution for this multiple optional filter?

How to show selected value using javascript in laravel

PDOException SQLSTATE[HY000] [2002] No such file or directory

WooCommerce - unset "<product> removed notice…" on cart page

merge all files in directory to one text file

HTML and PHP in one file

VichUploaderBundle error "Expected argument of type "File", "NULL" given" when submitting the form without selecting any file

How to remove from a multidimensional array all duplicate elements including the original?

About Contact Privacy policy Terms and conditions