Click here to Skip to main content
15,882,209 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
fatal error: uncaught mysqli aql exception: duplicate entry for kay primary in camp do 789 php php doc appointmentme - system index php: 36 stack trace: #0 camp php do app system index.php(56) mysqli_query (object (mysqli), insert into pa/) inserted in (main) exampp\htdocx.php/ piip doctor appointment system index.php line 56


What I have tried:

fatal error: uncaught mysqli aql exception: duplicate entry for kay primary in camp do 789 php php doc appointmentme - system index php: 36 stack trace: #0 camp php do app system index.php(56) mysqli_query (object (mysqli), insert into pa/) inserted in (main) exampp\htdocx.php/ piip doctor appointment system index.php line 56
Posted
Updated 14-Mar-23 9:07am
Comments
Member 15627495 14-Mar-23 10:17am    
without a piece of code causing trouble we can not help you.
please 'improve your question' with details and code

It's telling you you're trying to insert a record where you specified the primary key for the record and that key already exists in the table. You cannot do that. Every record in a table with a primary key must have a UNIQUE primary key value.

In a table where the primary key is automatically generated by the database, you DO NOT specify a value for the primary key. You just specify the values for all the other fields you need.
 
Share this answer
 
To add to what Dave has said, the most frequent cause of this is an INSERT statement where the columns are not listed:
SQL
INSERT INTO MyTable VALUES (...)
Instead the more explicit
SQL
INSERT INTO MyTable (Col1, Col2, Col3) VALUES (...)
When you do this, teh DB tries to insert values according to the current column order - and if you have an IDENTITY field that is usually both the Primary Key and the first field in the table definition. So despite the DB allocating it, your first value will try to go into the Primary key table and if that value exists, you get the error you have seen. (If it doesn't, you get a different error!)

Always list the column names in the order you will provide values - it prevents problem like this, and also reduces the chances for corrupting your database!
 
Share this answer
 
If you don't define a column as UNIQUE or Primary, you can use IGNORE, inside the INTO statement.
I strongly recommend using a column like UNIQUE, as it avoids duplicate records in your database.
Below is the example

SQL
<pre>INSERT IGNORE INTO MyTable (Col1, Col2, Col3) VALUES (...)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900