• 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

Display Brand Name Above Product Title in Woocommerce Cart, Checkout Page, Orders and Email Notification

VichUploaderBundle error "Expected argument of type "File", "NULL" given" when submitting the form without selecting any file

Add a custom text for a particular product on specific email notification in Woocommerce

Laravel Gates using model and returns "Using $this when not in object context" Line 28 of AzureUser model

How to properly set "0000-00-00 00:00:00" as a DateTime in PHP

PHPS source file - 403 Forbidden You don't have permission to access this resource

PHP password_verify

phpMyAdmin Accepts NULL in the NOT NULL field

PHPUnit (Phar) Fatal Error Only When Test Fails

PHP random string generator

Transform array, set each array element with parent key php

PHP Include for HTML?

Mysqli Output to a table

(Laravel) How to delete multiple models including optional relationships?

Nginx RTMP not recording

About Contact Privacy policy Terms and conditions