• 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

Sync Records With Default Values in Pivot Tables, Call to undefined method syncWithPivotDefaults()

Laravel Multi-language routes without prefix

PHP password_verify

PHP - Store information with NO database

Last order would be re-order in wooCommerce. How is it possible?

I'm trying to write a clean url for my website using the $_SERVER['REQUEST_URI'] in php

Cut an arabic string

Laravel 4 Redirect::back() not going to previous page (refreshing current page)

Remove "estimated for {country}" text after tax amount in Woocommerce checkout page

Laravel Delete and Update

Laravel csrf token mismatch for ajax POST Request

Is it possible to re-use an array taken from PHP via JSON in a $.ajax function?

Symfony - EasyAdmin - Add and remove functions are ignored from AssociationField

Symfony Error: "An exception has been thrown during the rendering of a template"

WordPress Security Standards want me to escape my html, but how to do it correctly?

About Contact Privacy policy Terms and conditions