Jump to content

Insert problem with forms


jackie11

Recommended Posts

Hi

I am having problem inserting data into my db via a form, I am getting the message up:

Duplicate entry '' for key 1


The code I'm using is:

[code]<?php
$user="root";
$host="localhost";
$password="";
$database = "employee_index";
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("employee_index") or die(mysql_error());

$sqlquery = "INSERT INTO employee (Employee_ID, Surname, Forename, Job_title, Office_location, Telephone, Email, Expertise, Hobbies, DOB, Picture)
VALUES ('$_post[Employee_ID]','$_post[Surname]','$_post[Forename]','$_post[Job_title]','$_post[Office_location]','$_post[Telephone]','$_post[Email]','$_post[Expertise]','$_post[Hobbies]','$_post[DOB]','$_post[Picture]')";

$result = mysql_query($sqlquery)
or die (mysql_error());

?>

[/code]

I have tried a number of different ways to set this up but none of them are working

Can anyone see where I am going wrong? :'(

Jackie
Link to comment
Share on other sites

The error actually refers to your data.

You are manually entering in data for your 'primary key'.  The primary key must be unique.  Most people set their primary key as auto_increment and then don't assign it a value at all.. the database takes care of that by the first record inserted is 1 second is 2 and so on....

Check your primary key... then check the record you are inserting.  You'll notice there is a record that already exists and the value of the primary key exists.
Link to comment
Share on other sites

Hi

Thanks for the reply, I have tried this and changed my Employee_ID to an auto increment and removed this field from the form, the problem is now when I add in details into the form and press submit the db creates a new row but does not forward the information I have added on the form, any suggestions! :-\

Jackie
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.