![]() |
Check that values aren't the same
I am playing around (locally). I want to make up a sign up form for this cms-like thing I am building. I want to make sure that the user login and e-mail aren't in the db already.
My SQL Statement is: Code:
INSERT INTO tbluser Quote:
|
I think (off the top of my head) I've always done this with two seperate statements. Not sure if it's the best way but it does work. Something like:
PHP Code:
|
Why are you wanting to know this information? Essentially, my reason for asking is that you could check this information on
INSERT, if you wanted to. Therefore saving you a SELECT statement. |
@Wildhoney, can you show me an example? All the examples I could find have the SELECT statement.
|
You'll need to configure the indexes on your table. So the username and email address fields would become unique indexes. When you then attempt to
INSERT into the table, an error will be thrown. This can be retrieved using the MySQL error number, and then handed accordingly.It saves on a SELECT statement to check if it is unique or not. |
Put spaces between every line in the string, I noticed that the error said "tbluserWHERE NOT", it should be "tbluser WHERE NOT" with a space between tbluser and WHERE.
I've been writing queries all day, that is a common error I hit unless I make sure there was a space at the end of every line in the string. |
It also doesn't appear that string values are wrapped with quotes.
|
| All times are GMT. The time now is 05:18 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0