• 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

SQL AVG() to 2 decimals

Symfony - EasyAdmin - Add and remove functions are ignored from AssociationField

CONCAT columns with Laravel 5 eloquent

is there any way to validate a field that sometime is File(image) && sometime is String(Src of same image)

Match csv filenames to table names and import

Select option menu read from database and use it's values

How to send upload image through email

How to avoid terminal to catch error instead of Symfony profiler

How can I format this number correctly using PHP?

how to make my own auto increment in php?

PHP web3 ERC20 token function call

CodeIgniter 4: Like and Dislike Functionality

phpmyadmin : Depends: php-twig (>= 2.9) but 2.6.2-2 is to be installed. WHAT?

wordpress : How to specify the cause "This site can’t be reached"

How to map the two arrays with a duplicate value?

About Contact Privacy policy Terms and conditions