473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Duplicate entry 'something' for key 2

114 100+
Dear Sir,

I have setup a SQL database with PHP. Whenever I am trying to insert the data into my database it gives me error : 'Duplicate entry for key 2'. Please help me sir.

I am sending you the coding for insert data.


<?
include("session.php");
session_start();
include("config.php");

$iata = $_POST['iata'];
$name = $_POST['name'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$companyname = $_POST['companyname'];
$city = $_POST['city'];
$state = $_POST['state'];
$province = $_POST['province'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$cemail = $_POST['cemail'];


$query = ("INSERT INTO $SQL_USR_TBL (iata, name, email, username, password, companyname, date, city, state, province, country, phone, fax, cemail) values('$iata', '$name', '$email', '$username', '$password', '$companyname', now(), '$city', '$state','$province', '$country','$phone','$fax','$cemail')");

$result = mysql_query($query);
if(!@mysql_query ($query)) {
echo mysql_error();
}else{

echo "Thank you for registration.";
//header("location:main.php");
exit;
}

mysql_close();
?>





And below are the database setup fields:


CREATE TABLE `user` (
`id` int(11) NOT NULL auto_increment,
`iata` int(14) NOT NULL default '0',
`name` varchar(255) NOT NULL default '',
`email` varchar(255) NOT NULL default '',
`username` varchar(255) NOT NULL default '',
`password` varchar(255) NOT NULL default '',
`companyname` varchar(255) NOT NULL default '',
`date` datetime NOT NULL default '0000-00-00 00:00:00',
`city` varchar(255) NOT NULL default '',
`state` varchar(255) NOT NULL default '',
`province` varchar(255) NOT NULL default '',
`country` varchar(255) NOT NULL default '',
`phone` int(255) NOT NULL default '0',
`fax` int(255) NOT NULL default '0',
`cemail` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) TYPE=MyISAM AUTO_INCREMENT=8 ;




Please help me Sir.

Thanks
Deepak
Dec 8 '06 #1
3 3542
michaelb
534 Expert 512MB
There are two unique keys in your table, one is on column id, which gets its value automatically from a sequence generator, another one is on the column "username"

I think that the error you're getting is generated when you're trying to insert a duplicate value into this column.
Considering what's in the table you probably don't want to have multiple records for the same username, so I guess you have two options here:
1. check whether given username exists before doing insert.
If it exists issue the appropriate warning and ask user to select a different username.
2. if this is an existing user than perhaps the purpose would be to update his or her record with new data, instead of creating a new record.
Dec 8 '06 #2
ronverdonk
4,258 Expert 4TB
deepak: after having started 13 threads you should know by now that you have to show your code with php, code or html tags!!

It is time you read the Posting Guidelines that apply to this forum.

moderator :cool:
Dec 9 '06 #3
michaelb
534 Expert 512MB
Ah, I've been quilty too, thanks for reminder!
michael
Dec 9 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: marx | last post by:
I have a bit of a problem and any help would be much appreciated. Problem: I have two dropdown list boxes with same data(all data driven). These are used for two separate entries. For every...
12
by: Jared Carr | last post by:
First I wish I knew how this was caused but here is our problem. Sometime in the recent past we got a duplicate table. Here is the result of a pg_dump with a pg_restore for just that table. ...
4
by: sri2097 | last post by:
Hi all, I'm storing number of dictionary values into a file using the 'cPickle' module and then am retrieving it. The following is the code for it - # Code for storing the values in the file...
1
by: Joseph Chase | last post by:
I am running version 4.1.13a-log on a Mac XServe. How can I receive a 'duplicate entry' error for an UPDATE? An update isn't creating an entry, so why this error message? ...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
8
by: Iona | last post by:
Hi Allan, I'm using a nifty piece of code you put on here some time back to do a duplicate entry check as below. I'm using to check for duplicate names. However I am getting an error message on...
5
by: baur79 | last post by:
Hi guys i try to run this code in loop and to pass even the entry is duplicated def email_insert_in_db(email): sql="INSERT INTO emails (email) values ('%s') "%(email)...
1
by: chicago1985 | last post by:
I have a unique constraint in my Oracle table for 3 fields. If I enter duplicate info on the table using Oracle client I will get an Ora message error ORA-00001 that tells me it is a duplicate entry...
2
by: olcaygul | last post by:
hii i´m learning jsp and html with sql and i´m beginer on it, i have the table andcodes below in mysql and jsp, i´m working on html and jsp with netbeans IDE 3.6. of course if i try to insert any...
4
by: AXESMI59 | last post by:
have a project in which I am entering Serial Numbers and Date codes into a Combo box. Serial numbers are all different. However, they could each have the same Date Code. Each Serial Number has a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.