• 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

How to increase the PHP upload limits [duplicate]

Smarty: undefined extension class 'Smarty_Internal_Method_Get_Template_Vars'

Warning: A non-numeric value encountered

Doctrine ORM: Excluding Records Based on Values of Nested Relationships

Toggle between a textbox and a select using PHP

Laravel : How to Create Dropdown to Select FOREIGN KEY from Other Table?

How can I make a full text index of the column?

enroll_table three field fetch to payment form to create payment field in laravel 5.5

MySQL order by field in Eloquent

MySQL default time format UTC or GMT?

Why getting "Build step 'Execute shell' marked build as failure" error while creating a backup tar for files

WordPress Subquery returns more than 1 row on SELECT

How to send image,audio or video through the WhatsApp API - PHP

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

Laravel print last executed SQL query with Query log

About Contact Privacy policy Terms and conditions