jobs1109 Posted September 29, 2011 Share Posted September 29, 2011 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       <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 More sharing options...
codeprada Posted September 29, 2011 Share Posted September 29, 2011 You're trying to enter duplicate keys (primary, unique, composite). Do you have an auto incremented ID in the company table? Link to comment https://forums.phpfreaks.com/topic/248139-error-duplicate-entry-for-key-1/#findComment-1274206 Share on other sites More sharing options...
jobs1109 Posted September 30, 2011 Author Share Posted September 30, 2011 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 https://forums.phpfreaks.com/topic/248139-error-duplicate-entry-for-key-1/#findComment-1274332 Share on other sites More sharing options...
codeprada Posted September 30, 2011 Share Posted September 30, 2011 You're entering the Company Name in the ID column. You should make ID an auto_increment INT. Link to comment https://forums.phpfreaks.com/topic/248139-error-duplicate-entry-for-key-1/#findComment-1274349 Share on other sites More sharing options...
Buddski Posted September 30, 2011 Share Posted September 30, 2011 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 https://forums.phpfreaks.com/topic/248139-error-duplicate-entry-for-key-1/#findComment-1274350 Share on other sites More sharing options...
jobs1109 Posted September 30, 2011 Author Share Posted September 30, 2011 Hi thank you very much it's working now. Link to comment https://forums.phpfreaks.com/topic/248139-error-duplicate-entry-for-key-1/#findComment-1274360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.