• 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 get rid of ampersand using WP Nonce URL and WP Redirect or PHP header

Eloquent insert id with sequence next value

I cannot create a auto generated date time in mysql workbench

PHP | "The requested PHP extension bcmath is missing from your system."

Laravel phpunit test failing authorization

Send POST data via raw JSON with Postman

Google Gmail API - How to login programatically?

How to loop a tree array with unknown depth and get array blocks?

Make Calculator - When Button clicked the No shows in Textbox.

GA4 custom event from server side, can someone tell me how i can do the following code in php?

How to check user Permissions using Custom Middleware in Laravel

Assets not referencing to public folder (Laravel)

PHP SoapClient: set a namespace without prefix

How to use React Router with Laravel?

Required field only if another field has a value, must be empty otherwise

About Contact Privacy policy Terms and conditions