• 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 prevent float variables displaying as scientific notation when printing [duplicate]

Laravel Displaying image from database

Getting output of MS stored procedure on php call

Limit login attempts in Laravel 5.7

Laravel Excel::store file empty after stored

Laravel Carbon throws error The format separator does not match

Telegram bot doesn't answer

PHP only Hit Counter?

Laravel Unresolvable dependency resolving [Parameter #0 [ <required> $method ]] in class GuzzleHttpPsr7Request

Hide specific products from unlogged users based in product category in WooCommerce

Laravel Blade checkbox not checked

How to render html from a @foreach loop in a textarea

How to change product Image when variables are selected in Shop and Archive Pages?

How to execute sql code based on fetch array

PHP 8.1: strftime() is deprecated

About Contact Privacy policy Terms and conditions