• 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

CodeIgniter 4: Like and Dislike Functionality

Shopify password update using Shopify API

Move a child array to parent array and change parent/child name

Laravel : How to Create Dropdown to Select FOREIGN KEY from Other Table?

PHP function Not Working As Expected From functions.php Include File

Wordpress add responsive srcset header image to theme

Smarty: undefined extension class 'Smarty_Internal_Method_Get_Template_Vars'

php mysql + create a friend request system

How to give apache permission to write to home directory?

Dynamic dropdown Ajax PHP request

The difference when using if statement true === something() vs something() === true [duplicate]

Cut an arabic string

How can I make good efficent AJAX live forms with just jQuery and

How to disable only_full_group_by option in Laravel

How to set dynamic `home` and `siteurl` in WordPress?

About Contact Privacy policy Terms and conditions