Jump to content

Error: Duplicate entry '' for key 1


jobs1109

Recommended Posts

Hi I am getting this error message and don't know why. please help this is the message " Error: Duplicate entry '' for key 1 "

 

 

Here is the code

 



<?php

include'../DB-connection.php';

$sql="INSERT INTO Company(CompanyName,Address,Logo,PhoneNumber,ContactPerson)

VALUES('".mysql_real_escape_string($_POST[CompanyName])."',

	'".mysql_real_escape_string($_POST[Address])."',

	'".mysql_real_escape_string($_POST[Logo])."',

	'".mysql_real_escape_string($_POST[PhoneNumber])."',

	'".mysql_real_escape_string($_POST[ContactPerson])."')";





if(!mysql_query($sql,$con))

{

die(' Error: '. mysql_error());

}

echo " <center>your compnay info added &nbsp &nbsp &nbsp <a href='User-Login.php'>Login to Post a job</a> </center>" ;

mysql_close($con)

?>



Link to comment
Share on other sites

Here is the structure for the table

 



--
-- Table structure for table `Company`
--

CREATE TABLE IF NOT EXISTS `Company` (
  `id` varchar(25) NOT NULL,
  `CompanyName` varchar(100) NOT NULL,
  `Address` varchar(100) NOT NULL,
  `Logo` varchar(100) NOT NULL,
  `PhoneNumber` varchar(25) NOT NULL,
  `ContactPerson` varchar(25) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;




Link to comment
Share on other sites

You're entering the Company Name in the ID column.

Is incorrect, the SQL query is correctly structured, the issue is the ID column is not an AUTO_INCREMENT integer

 

The table structure should be, or something similar.

CREATE TABLE IF NOT EXISTS `Company` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `CompanyName` varchar(100) NOT NULL,
  `Address` varchar(100) NOT NULL,
  `Logo` varchar(100) NOT NULL,
  `PhoneNumber` varchar(25) NOT NULL,
  `ContactPerson` varchar(25) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

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.