• 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

Laravel Pagination links() not working

find in set in laravel ? example

Reorder attribute dropdown terms in Woocommerce single variable products

Laravel/docker-compose/redis - Class 'Redis' not found

Cannot pass null argument when using type hinting

How can I make this nested location configuration use the correct path to call a php program?

How to test a php login connected to a mysql db through xampp?

Problems getting instance of UploadedFile in Yii2

How to submit the custom form data in database in WordPress without plugin using ajax?

how to check version of codeigniter framework?

Autoloading classes in PHPUnit using Composer and autoload.php

PHP array, move keys and values to new array, but mix it up

How can I make a full text index of the column?

How to change 'users' auth table and use another instead Laravel

Laravel - Browser displays message again when I press back button

About Contact Privacy policy Terms and conditions