• 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

Getting public posts of a random user from Facebook API

Adding hreflang tags automatically in WordPress subdirectory multisite

Only on Firefox "Loading failed for the <script> with source"

Use same method for inertia response and json response Laravel Jetstream

Why i get wrong output for html markdown?

Filter array by skipping every nth element from the end

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

merging two arrays with specified index

Is there a way to use Foundry Model for Authentification inside Functional Tests?

(PHPUnit) PHP Fatal error: Uncaught Error: Call to undefined function each()

How to install PHP composer inside a docker container

Destroy session upon refresh

MOODLE: What does it mean to aggregate h5p assets?

How to get multiple values with same key from an array PHP

jwt decode throws Invalid argument supplied for foreach() on php-jwt and codeignitor 4

About Contact Privacy policy Terms and conditions