• 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

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

Magento 2 - How to add new block to admin panel in product page?

Display a product custom field only in WooCommerce Admin single orders

I want to store data in new index as per my key in php [duplicate]

How do I truncate a decimal in PHP?

I want to display default profile image if user do not have profile image

How can I get new CSRF token in LARAVEL by using ajax

Add and update products to session cart in Laravel

virtctl works when executed via command line but not from php exec()

How to test a php login connected to a mysql db through xampp?

Edit product hook WooCommerce

How to add a custom field to all Woocommerce attribute terms using add_action

Star and Half Star Rating in Laravel

How can I create a Download Page with post php method?

PHP's array_map including keys

About Contact Privacy policy Terms and conditions