Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Error in SQL Insert statement

Posted on 2007-07-22
5
Medium Priority
?
210 Views
Last Modified: 2007-07-22
Home come I am getting this error when trying to insert a new row in a table?

Duplicate entry '0' for key 1

This is my sql insert statement:

$sql_insert = mysql_query("INSERT INTO Replies (strReply, strReply_Name, strTime) VALUES ('$strReply', '$strReply_Name', '$strTime')") or die(mysql_error());
0
Comment
Question by:pingeyeg
  • 2
  • 2
5 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 400 total points
ID: 19543243
>Duplicate entry '0' for key 1
means that you have a unique contraint/index or primary key in the table to which you try to insert a duplicate.
what is your table design?
0
 
LVL 4

Accepted Solution

by:
punkstar earned 1600 total points
ID: 19543245
In phpmyadmin, set your 'intReply_ID' column to have "auto_increment" in the "extra" drop down. Assuming you are using phpmyadmin, otherwise run this query:

ALTER TABLE `Replies` CHANGE `intReply_ID` `intReply_ID` INT( 11 ) NOT NULL AUTO_INCREMENT

Got the iniReply_ID column name from your last question. Change it to the correct name if I am wrong.

Hope it helps.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 19543247
Table: Replies

Fields: intReply_ID, strReply, strReply_Name, strTime
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 19543253
Wow how did I miss that.  I thought I had already assigned both ID's in my tables to auto-increment.  I guess it didn't take or something.  Anyway, thanks!
0
 
LVL 4

Expert Comment

by:punkstar
ID: 19543270
No problemo.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question