• 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 to validate Envato Purchase Code in PHP

PHP: How to quickly split a key=value file into associative array

How to properly start Laravel 8 with Bootstrap & authentication

(Cache::lock()) -> get() -- Under what conditions does it return false?

Failed user login on production server using Symfony framework (Authentication request could not be processed due to...)

php curl_exec() Connection refused when retrieving a remote image

Get WooCommerce product variation attribute terms in admin products general box

How to identify whether webp image is static or animated?

Getting output of MS stored procedure on php call

How do I refresh a DIV content?

How to find the date a user created their Google account

Applying programmatically a coupon to an Order in WooCommerce3

Correct way to use LIKE '%{$var}%' with prepared statements?

PDOException: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: no such host known

Phalcon: setStatusCode returns empty response

About Contact Privacy policy Terms and conditions