• 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 redirect to another page and call a Function there on Angular ng-click

Symfony there are no commands defined in the "make" namespace

How to get median and quartiles/percentiles of an array in JavaScript (or PHP)?

laravel sanctum Route [login] not defined

Cannot connect to own websocket server when on secured domain

Get sql.h error on MacOS 12 (Monterey) sqsrv and pdo_sqsrv drive installation

Backend cannot be reached after Typo3 login screen

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

Array to string conversion

Correctly determine if date string is a valid date in that format

Merge column values from two arrays to form an indexed array of associative arrays

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

How to get unique slug to same post-title for other time too?

Transform array, set each array element with parent key php

Too few arguments to function PendingResourceRegistration::name(),1 passed in C:xampphtdocsproject outesweb.php on line 18 and exactly 2 expected

About Contact Privacy policy Terms and conditions