Jump to content

Key 2 'username' already exists


grandadevans
 Share

Recommended Posts

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 with
Key 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 enter
sara
saratrolley
saraanne
sara1
Only 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 happening

This 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]
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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 all
John
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

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.

 Share

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