• 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

Prestashop cUrl Login

Custom Button next to “ADD TO CART” button of WooCommerce based on Product Type

Laravel after login Two factor not working

Adding reCAPTCHA v2 into my PHP file

Json_Encode not returning html even i try to encode JSON_HEX_QUOT | JSON_HEX_TAG

Getting output of MS stored procedure on php call

error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure

Add record for each array elements if missing in table

Natural ORDER in Laravel Eloquent ORM

Webscraping Symfony/Panther: Can't get HTML

Cut an arabic string

laravel 5.6 bulk inserting json data

PHP Form Not Inserting

Not able to access model in the controller mautic

How to Make Laravel Eloquent "IN" Query?

About Contact Privacy policy Terms and conditions