• 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 do I Post to .txt document before form submits

How to make a array inside array?

Apply filter array/return terms

HTML and PHP in one file

Add Metadata, headers (Expires, CacheControl) to a file uploaded to Amazon S3 using the Laravel 5.0 Storage facade

Laravel set default language not working

SQL AVG() to 2 decimals

oauth-private.key does not exist or is not readable

Object of class stdClass could not be converted to string error

Laravel Schedule not sending email

Get keys from associative array [duplicate]

Target Individual Form Instance/Counter Inside A PHP While Loop

Can't exclude directories from .htaccess mobile redirect?

Error converting docx to pdf using Unoconv

Elastic Beanstalk with Laravel Envoy

About Contact Privacy policy Terms and conditions