• 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

Get all WooCommerce products within own plugin

Laravel 5 controller sending JSON integer as string

Unable to Edit config.inc.php

Entity provider not working in security.yml php symfony3.4 ({"code":401,"message":"bad credentials"}.)

Warning: A non-numeric value encountered

mysql slow on updates for a well optimized query

Lexik JWT authentication problem "Invalid credentials"

Docker & Laravel : configure: error: Package requirements (oniguruma) were not met

Laravel s3 upload file with metadata using pre-signed url

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

How to install PHP composer inside a docker container

enable Apache http Authorization header

renameColumn migration fails for existing column with columns does not exist error

PHP array sort and remove duplicates by two field values

How to average columns of data from multiple, flat arrays?

About Contact Privacy policy Terms and conditions