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 7409433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:04:56+00:00 2026-05-29T06:04:56+00:00

I have code similar to the following: $sql2 = ALTER TABLE table ADD UNIQUE(field2,

  • 0

I have code similar to the following:

$sql2 = "ALTER TABLE table ADD UNIQUE(field2, feild3, field4, field5);";    
$sql2 .= "INSERT IGNORE INTO table (field1, field2, feild3, field4, field5) VALUES ('$_POST[field1]','$_POST[field2]','$_POST[field3]','$_POST[field4]','$_POST[field5]')";

if (!mysql_query($sql2,$con))
{
    die('Error: ' . mysql_error());
}
echo "1 record added";
}

I have found that I get an error if the table already has two rows which are the same but works well otherwise. I am worried that if I add the duplicates from two different sources that they will both be added to the table and later requests will trigger the error I got earlier because of the two almost identical rows. Is it possible to add two almost identical rows as shown above if the php file is executed at the same time from two different sources?

EDIT: FYI The code is a snippet from a larger program. I am sending data from an android app I am working on to the $_POST fields

  • 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-05-29T06:04:57+00:00Added an answer on May 29, 2026 at 6:04 am
    1. mysql_query DOES NOT ALLOW execute two queries in single call

    2. insert ignore won’t return error when duplicate found (that’s why it named as ignore)

    So, the FIRST error is caused by the alter ...; insert ...

    Then alter table is require execute once only,
    on your next execution, you are no longer require to perform alter table (again).
    Otherwise, you will getting the duplicate INDEX error (trying to add an existing index)

    For the unique index, is meant to prevent duplicate,
    so, it only will have one unique record (no matter what)

    And for you funny almost identical,
    it will never happen

    it blocked when duplication found on field 2..5

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML file that has code similar to the following. <table> <tr>
I have code similar to the following in many places: var dbParams = db.ReadParams(memberID,
I have code similar to the following with a URL like this... If I
In a CUDA kernel, I have code similar to the following. I am trying
I have Perl code similar to the following: # -- start -- my $res;
I have ASP.Net code similar to the following (this is inside a FIELDSET): <ol>
We have similar code to the following in one of our projects. Can anyone
I have code, similar to the following, that I would like to modify: Sub
I've got code similar to the following... <p><label>Do you have buffet facilities?</label> <asp:RadioButtonList ID=blnBuffetMealFacilities:chk
I have the following JQuery code which does similar functionality like Stackoverflow where the

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.