• 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

HTML + PHP + PHPMAILER

How to get an Array value inside an object in an array Php [duplicate]

Form Validation and Submission to database

PHP code for generating decent-looking coupon codes (mix of letters and numbers)

No definition found for function in vendor vscode

How can I format this number correctly using PHP?

How To Access A Column In M-M Relationship Table In Laravel

PHP web3 ERC20 token function call

Laravel Get Days In Month From Month Number?

Fatal error: Uncaught mysqli_sql_exception: Unknown database 'test' in ... (How do I fix that? Using PHP)

Laravel Database Strict Mode

Add customer email and phone in "Order" column to admin orders list on Woocommerce

Laravel 5 issue with wherePivot

dompdf and img tag, image wont show

Multiple order by in WooCommerce

About Contact Privacy policy Terms and conditions