Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7872243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:08:52+00:00 2026-06-03T02:08:52+00:00

I have a mysql db with two tables. The first table is called ‘uniqueReferences’

  • 0

I have a mysql db with two tables. The first table is called ‘uniqueReferences’ and the second one ‘duplicatedReferences’. The two tables have two fields only: an id field (auto-incremented) and a field called Reference. What I would like is as follows. When trying to insert a ref in the ‘uniqueReferences’ table, if the reference already exists, do not insert it in that table but in the table ‘duplicatedReferences’.

So what I tried but did not work is the following.
1-> set the field reference of my ‘uniqueReferences’ table as ‘unique’.
2-> Make the following

try{  
         $req = $prepared_insertQry_toUniqueRefTable -> execute(array(something));

         if($req == 0){
               $prepared_insertQry_toDuplicateRefTable->execute(array(something));
         }
     }
    catch(PDOException $e){echo $e->getMessage();}

This is unfortunately not working. I have the following error SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry. Hope someone can help. Cheers. Marc

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:08:54+00:00Added an answer on June 3, 2026 at 2:08 am

    See my notes inline with the code:

        try{  
             $req = $prepared_insertQry_toUniqueRefTable -> execute(array(something));
    
             // this never executes because an Exception halts it here
             /*if($req == 0){
                   $prepared_insertQry_toDuplicateRefTable->execute(array(something));
             }*/
         }
        catch(PDOException $e){
           // this catch grabs the exception and executes the code within instead
           // that code might log an error, echo the error message, or perform
           // alternative logic. In your case you want to execute alterntative logic
           // ie. your query
           $prepared_insertQry_toDuplicateRefTable->execute(array(something));
    
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a MySQL database I have two tables linked in a join. One table
i have two mysql tables. the first is called chosen and consists of id,
I have a script in MySQL that creates two tables, the second table references
using php and mysql I have two tables, a users table and a profiles
I'm new to MySQL and PHP. I have two tables, one to hold all
I have the same trigger on two tables. The first one: CREATE TRIGGER updateURL1
So I have two seperate tables. In the first table, there are a bunch
i want to do one thing on my mysql DB. I have two tables:
that´s my first question in stackoverflow . I have two MYSQL tables: categories and
i have two mysql tables tableA colA1 colA2 1 whatever 2 whatever 3 whatever

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.