• 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

Undefined Array Key error when uploading image on php

Error Class "LaravelFortifyFeatures" not found

mysql slow on updates for a well optimized query

I'm trying to use curl with php but getting this error:Could not resolve host: Bearer

How to skip cart page on woocomerce for certain products only?

Laravel whole batch is cancelled if one Job fails

How to find phpcs current default standard

args[max_input] woocommerce if statement confused

how to make my own auto increment in php?

Magento 2 - Controller returning blank page

merging two arrays with specified index

Xdebug can't connect back to Docker host

if statement inside concatenation

500 (Internal Server Error) with Laravel & Docker [duplicate]

How to auto populate preferredCountries from intl-tel-input with db output

About Contact Privacy policy Terms and conditions