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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:15:16+00:00 2026-06-08T14:15:16+00:00

I am getting duplicate entry error for primary key which is autoincrement field defined

  • 0

I am getting duplicate entry error for primary key which is autoincrement field defined in table.

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: 
Integrity constraint violation: 1062 Duplicate entry '0' for key 1' in

I am trying to add an entry to the table at the almost same time. That could be the possible reason but i am not sure.

Actually multiple ajax call running behind the scene and they are sometime trying to add entry in table with same primary key at the same time.

I guess this is the issue of autogeneration of same primary key by sql engine.

Mysql table type:MyISAM.

What can be done to fix this?

Table definitions: result_id is a primary key field

Table defintion

I have writren PDO wrapper for database entry, although i am using this databound object from last year and no issues found. Attaching some portion as requested in comment.

Note: ID(primary key) is not a part of INSERT statement.

$valueList = "";
$query     = 'INSERT INTO ' . $this->tableName . ' (';


foreach ($this->relationMap as $key => $value) {
    eval('$actualVal = &$this->' . $value . ';');

    if (isset($actualVal)) {
        if (array_key_exists($value, $this->modifiedRelations)) {
            $query .= $key . ', ';
            $valueList .= ":$value, ";
        }
    }
}


$query = substr($query, 0, strlen($query) - 2);

$valueList = substr($valueList, 0, strlen($valueList) - 2);
$query .= ") VALUES (";
$query .= $valueList;
$query .= ")";
//prepare and execute codes - here
$this->ID = $this->objPDO->lastInsertId();
  • 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-08T14:15:18+00:00Added an answer on June 8, 2026 at 2:15 pm

    Read this

    Or

    You have set result_id already in primary key according to your sanpshot

    but i think you have not set is auto_increment

    Please set primary key with auto_increment

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

Sidebar

Related Questions

Alright, so I'm getting the error: #1062 - Duplicate entry '0' for key 'PRIMARY'
I'm getting a Duplicate entry 'blah' for key 'username' error message, but I would
I'm getting the following error while executing database query: Error Number: 1062 Duplicate entry
I am getting duplicate error in my xcode while build and run I have
I'm stuck on a mySQL query using ON DUPLICATE KEY UPDATE. I'm getting the
I am getting an unwanted duplicate entry for every last row on an insert
After mime parsing I am getting email body with duplicate entry(plain n html) and
I keep getting errors like this in my Product.wxs file. The primary key 'ExitDialog/Finish/EndDialog/Return/1'
I keep getting duplicate entries in my database because of impatient users clicking the
Possible Duplicate: Getting specific days in a month I've touched on this problem once

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.