• 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

What is my SQL missing?

PHP -> Next nearest date defined by array of days in week

Error when uploading certain .png files "Interlace handling should be turned on when using png_read_image"

How to convert a carbon into string, to take the date only?

Jquery DataTables: Data not displaying in table via Ajax

how to youtube api data to print in toolset metabox using a button click before save-post

How to set time with DateTime modify?

Detect a fetch request in PHP

Filter array by skipping every nth element from the end

How to connect to MSSQL Server with PHP from Ubuntu 18.04?

Refresh specific HTML content that retrieves data from MySQL

how can I set a session variable in Drupal 8 and get it in a php script?

Prevent blank space in pdf pages (DomPdf)

Laravel views are showing from cache on one server but works fine on other server

Laravel multi auth - Authentication user provider [] is not defined

About Contact Privacy policy Terms and conditions