Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking if username exists (when editing u/n) 1

Status
Not open for further replies.

calv1n

Programmer
Sep 29, 2007
18
CA
I'm having some troubles when editing an admin on my script.

For example when the username stays the same, I get the 'username exists' message.

Code:
                is_admin();

                require '../lib/config.php';

                connectcp();

                $result = mysql_query("SELECT username from admin where username='$username'");
                list($usernametocheck) = mysql_fetch_row($result);

                if (!$usernametocheck) {
                        //good!
                } else {
                        CPMessage("Username Exists", "The username you have chosen already exists.", "");
                }

Incidently, this code snippet is the exact one I use on the 'add admin' function on my script, so I know why it isn't working, just can't find a way to solve it. :-(

Thanks.



-CALV1N
 
I'm not sure I understand... If you are editing a user, it implies it already exists, so why are you checking for it?. What exactly are you trying to do?



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
i.e if they try to change their name to another one which already exists.




-CALV1N
 
O.k. so the what's the problem? When the name stays the same you don't check for it. If the name changes, then you check to see if its already in the DB.


Keep a hidden value with the original name, and check it against the name gotten from the form. if they match they you can skip the name check.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thank you for your help. I fixed it. :-D

-CALV1N
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top