Jump to content

Why is this query doing this?!?!


reportingsjr

Recommended Posts

I am creating a register out of php/sql and I have this coding:

$query2 = "INSERT INTO `users` VALUES ('" . $_POST['username'] . "', '" . $password . "', '" . $_POST['admin'] . "')";

But every time I test it I will get an error like this: Error in query: INSERT INTO `users` VALUES ('t', 'tes', 'no'). Duplicate entry 't' for key 1What should I do about this? It is kind of annoying.. Thanks!

Link to comment
Share on other sites

I've never seen a query look like this before. Perhaps try

$query2 = "INSERT INTO `users` VALUES ('$_POST[username]', '$password', '$_POST[admin]')";

It probably won't make a difference, but you can try anyways. That's the only thing I can think of first off.

Link to comment
Share on other sites

The username field is a unique field, it's the primary key. That means that it needs to be different for each record in the table. So you are getting the error because there is already a record with username "t". You need to search the database before you insert that.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...