• 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

"properties should not be accessed directly" issue during WooCommerce 3.0 checkout

How to upload mpdf file after generating to s3 bucket in php

Undefined Array Key error when uploading image on php

Reading input in php from terminal

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables 11 [closed]

Check if user online laravel

How to disable only_full_group_by option in Laravel

How to extract price from given url using Xpath?

How to solve cURL error 60: SSL certificate in Laravel 5 while Facebook authentication

How to Make Laravel Eloquent "IN" Query?

How to test laravel controller method?

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

How to run or debug php on Visual Studio Code (VSCode)

How to get array values using foreach in laravel

PHPMyAdmin not working as intended at remote server. Error 500, $respond not found

About Contact Privacy policy Terms and conditions