jackie11 Posted January 19, 2007 Share Posted January 19, 2007 Hi I am having problem inserting data into my db via a form, I am getting the message up: Duplicate entry '' for key 1The 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 https://forums.phpfreaks.com/topic/34823-insert-problem-with-forms/ Share on other sites More sharing options...
kevinkorb Posted January 19, 2007 Share Posted January 19, 2007 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 https://forums.phpfreaks.com/topic/34823-insert-problem-with-forms/#findComment-164147 Share on other sites More sharing options...
jackie11 Posted January 19, 2007 Author Share Posted January 19, 2007 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 https://forums.phpfreaks.com/topic/34823-insert-problem-with-forms/#findComment-164520 Share on other sites More sharing options...
micmania1 Posted January 19, 2007 Share Posted January 19, 2007 Change $_post to $_POST.Should work fine. Link to comment https://forums.phpfreaks.com/topic/34823-insert-problem-with-forms/#findComment-164531 Share on other sites More sharing options...
jackie11 Posted January 19, 2007 Author Share Posted January 19, 2007 HiThat works great many many many thanks to you all!!!!It feels soooo good when you have been working on something for ages and it finally works!Well I must move on to my next problem ha ha ha!!!!Thanks againJackie Link to comment https://forums.phpfreaks.com/topic/34823-insert-problem-with-forms/#findComment-164544 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.