Error in SQL Insert statement

Posted on 2007-07-22
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());
Question by:pingeyeg
    LVL 142

    Assisted Solution

    by:Guy Hengel [angelIII / a3]
    >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?
    LVL 4

    Accepted Solution

    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.
    LVL 1

    Author Comment

    Table: Replies

    Fields: intReply_ID, strReply, strReply_Name, strTime
    LVL 1

    Author Comment

    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!
    LVL 4

    Expert Comment

    No problemo.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now