Forum Moderators: open

Message Too Old, No Replies

PHP MySql problems with checking username in use

trying to figure out how to check if a mysql table already has a username

         

MrWhippy

11:26 pm on Jan 21, 2008 (gmt 0)

10+ Year Member



Hi all,

i have no idea as to how to go about this but have come up with something i think should work, but does not.

basically i have a script to insert a new user into a DB table with varying info, the usual i guess. what i am trying to do is to check to see if the username entered at registration is already in use.

$user_name_check = mysql_query("SELECT * FROM test
WHERE user_name=$UserName");
//check to see if the username already is in use
if (eregi($user_name_check, $UserName))

this is the code i thought may do it, however i get the following error

Warning: eregi() [function.eregi]: REG_EMPTY in C:\wamp\www\Sale\newuser.php on line 25

line 25 is the one with the eregi code on it.

am i barking completley up the wrong tree here or am i somewhere close.

many thanks for any help in advance,

even a pointer in the right direction along the lines of where i need to be looking would be nice.

mipapage

11:28 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...what i am trying to do is to check to see if the username entered at registration is already in use

Why not simply:

if($user_name_check == $UserName) {
// try again...
}

MrWhippy

5:08 pm on Jan 22, 2008 (gmt 0)

10+ Year Member



oh my word,

how did i miss that,

thanks mipapge, you have just saved me hours.

think the old lets find a difficult solution to a simple problem just kicked in then.

mipapage

5:18 pm on Jan 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Happen to us all, for sure. Sometimes I wonder why I do things the way they are, and only when I go thru version control do I see the strange path that lead me to an even stranger solution for some of the simplest of things :)