• 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 do I call a php file with axios?

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null

Project structure for PHP

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

Statement that checks whether a URL contains a particular path?

Laravel get user data with profile

advanced custom fields wordpress custom class

How to send image,audio or video through the WhatsApp API - PHP

Laravel Carbon throws error The format separator does not match

Adding custom body class to the custom archive pages

MISSING UPDATES FOR: MEDIA Drupal 9

How to solve Duplicate entry '0' for key 'PRIMARY' in Wordpress?

Undefined variable in Laravel 8 project (php 7.4)

WooCommerce: Add/display Product or Variation custom field everywhere

Component install error: JInstaller: :Install: File does not exist

About Contact Privacy policy Terms and conditions