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
https://forums.phpfreaks.com/topic/248139-error-duplicate-entry-for-key-1/
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;




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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.