grandadevans Posted May 29, 2006 Share Posted May 29, 2006 Hi,Can anybody help me? On my site there is a registration page, occassionaly I see that people are reloading the registration page 3 or 4 times but I cannot see why, I have contacted a few members who persisted until the entry went through and asked if they had any problems, to cut a long story short....The describe the fault as coming up withKey 2 'username' already exists.Obviously I have a field called username in the users database which is a unique key but the users have had to enter 3 or 4 entries until they succeed, the last one had to entersara saratrolleysaraannesara1Only the last one succeeded.On some users including whenever I test it through IE or Firefox it works fine, on others......well, you tell me! Does anyone have any ideas as to why this is happeningThis is the form field[code]<input name="username" type="text" id="username" value="<?php echo $_POST['username'];?>" />[/code]This is the input statement[code] $insertSQL = sprintf("INSERT INTO users (username, password, fName, sName, email, phoneType1, phoneNo1, phoneType2, phoneNo2, rank, corpRegt, unit, area, countryID, newsletter, `level`, dob, dateJoined, icon) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, '$newDate', '$date', '$thumbnail')", GetSQLValueString($_POST['username'], "text"), GetSQLValueString($_POST['password'], "text"), GetSQLValueString($_POST['fName'], "text"), GetSQLValueString($_POST['sName'], "text"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($_POST['phoneType'], "text"), GetSQLValueString($_POST['phoneNo'], "text"), GetSQLValueString($_POST['phoneType2'], "text"), GetSQLValueString($_POST['phoneNo2'], "text"), GetSQLValueString($_POST['rank'], "text"), GetSQLValueString($_POST['regt'], "text"), GetSQLValueString($_POST['unit'], "text"), GetSQLValueString($_POST['area'], "text"), GetSQLValueString($_POST['country'], "int"), GetSQLValueString($_POST['newsletter'], "text"), GetSQLValueString($_POST['level'], "text"));[/code]and this is the describe from the users table[code]mysql> DESCRIBE users;+------------+--------------+------+-----+-----------------+----------------+| Field | Type | Null | Key | Default | Extra |+------------+--------------+------+-----+-----------------+----------------+| userID | int(11) | NO | PRI | NULL | auto_increment || username | varchar(100) | NO | UNI | | || password | varchar(100) | NO | | | || fName | varchar(100) | NO | | | || sName | varchar(100) | NO | | | || email | varchar(255) | NO | | | || phoneType1 | varchar(15) | YES | | NULL | || phoneNo1 | varchar(30) | YES | | NULL | || phoneType2 | varchar(15) | YES | | NULL | || phoneNo2 | varchar(30) | YES | | NULL | || icon | varchar(255) | YES | | images/user.gif | || dob | date | YES | | NULL | || dateJoined | date | YES | | NULL | || rank | varchar(100) | YES | | NULL | || corpRegt | varchar(255) | YES | | NULL | || unit | varchar(255) | YES | | NULL | || area | varchar(255) | YES | | NULL | || countryID | int(11) | YES | MUL | NULL | || newsletter | varchar(10) | YES | | NULL | || level | varchar(100) | YES | | user | || posts | int(11) | YES | | 0 | || lastLogin | date | YES | MUL | NULL | |+------------+--------------+------+-----+-----------------+----------------+[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10707-key-2-username-already-exists/ Share on other sites More sharing options...
Honoré Posted May 29, 2006 Share Posted May 29, 2006 What is your problem?If the usernames sara, saratrolley and saraanne already existed in your database then it is normal that the user gets an error message saying exactly that.Probably sara1 was the first username not already in your database.Or do you have a problem elsewhere? Quote Link to comment https://forums.phpfreaks.com/topic/10707-key-2-username-already-exists/#findComment-39952 Share on other sites More sharing options...
grandadevans Posted May 29, 2006 Author Share Posted May 29, 2006 That's just it, out of all the 4 usernames that she tried to enter, only the last one went through butThere is NO sara'a apart fom herI have just confirmed it with a %sara% query, and there are only 60 something users so the list id not that extensive. Quote Link to comment https://forums.phpfreaks.com/topic/10707-key-2-username-already-exists/#findComment-39955 Share on other sites More sharing options...
fenway Posted May 29, 2006 Share Posted May 29, 2006 I have to agree with Honoré -- if the DB says there was a duplicate key error, then somewhere attempted to add an existing value. You can prove this easily from the command-line. Quote Link to comment https://forums.phpfreaks.com/topic/10707-key-2-username-already-exists/#findComment-40005 Share on other sites More sharing options...
grandadevans Posted May 29, 2006 Author Share Posted May 29, 2006 Right, I'm probably gonna sound like a complete muppet here but I have fixed it.After reading the advice of 2 people who know better than me, I got to thinking.The problem had to be somewhere in the script and it turned out to be a misplaced } bracket that meant it was trying to input the statement twice.Time to learn a lesson.Thanks again to allJohn Quote Link to comment https://forums.phpfreaks.com/topic/10707-key-2-username-already-exists/#findComment-40018 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.