Re: Is this an unique user name???

From: Date: Tue, 18 Feb 2003 12:13:57 +0000
Subject: Re: Is this an unique user name???
Groups: php.general 
Request: Send a blank email to php-general+get-135983@lists.php.net to get a copy of this message
> Ok... I am trying to have this registration page search a table in a db > to find out if the user name supplied is unique. Here is the syntax that > I used but it does not seem to work: > > <? > ..... > > $var_UserName = addslashes($_POST['User_Name']); > > ..... > > $query = "SELECT * FROM company_info WHERE UserName = '"; > $query .= $var_UserName."'"; > > $result = mysql_query($query); > > // This is where the problem come in... I tried these two options, both > // failed. > > //Opt1 > $num_results = mysql_num_rows($result); > > if( $num_results > 0 ) //this user name is not unique > { // exec the error methods.... } > else > { // add record to db } > > //Opt2 > if( $results ) // To my knowlegde ;) this would be true if $results > 0 > { // exec error } > else > { // add record } > > ..... > ?> > > Is there something that I am missing? Or actually doing wrong? If > anybody would need to see the whole script I would be glad to supply on > demand. > > Thank for your time, > -Alex > just an alternative to do what you want: $query = "SELECT count(UserName) as user_num FROM company_info WHERE UserName='$var_UserName'"; $result = mysql_query(); $data = mysql_fetch_array($result); $user_num = $data['user_num']; if($user_num > 1) { //if user is not unique } else { //if user is unique }

« previous php.general (#135983) next »