• 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

Laravel set default language not working

How do I truncate a decimal in PHP?

yii2 and mssql insert varbinary into model

How can I make Laravel return a custom error for a JSON REST API

How to fix Call to undefined method AppModelsTableName::factory?

PHPExcel_IOFactory::createWriter causes wrong behaviour

Sentry + Laravel: how to log an already catched Exception?

Star rating with half star support

HTTP Range requests with php for Video Embedding for solving going to specific time in video (seek bar not work)

Is there a way to correctly use sanitize_text_field and wp_unslash that doesn't cause psalm to error with "expects string, possibly different type"

Store / Website Column in Magento 2 Admin Grid - Custom Module

phpMyAdmin Accepts NULL in the NOT NULL field

PHP - CURL using HTTPS [closed]

Display Brand Name Above Product Title in Woocommerce Cart, Checkout Page, Orders and Email Notification

Backend cannot be reached after Typo3 login screen

About Contact Privacy policy Terms and conditions