|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I know what I want to do, don't know how exactly to go about it. Any help would be greatly appreciated.
I want to check a field for a certain value and return an answer in PHP so that I know whether or not to continue. Example: A user wants to register on the site. He goes to a register page, and it asks for his desired username, and a password. How can I check my table (say, TBLUSERS) for the name he entered, and return a true/false value, checking if someone already has that name? Mike |
|
#2
|
|||
|
|||
|
Well, you can always MacGuyver up a while loop to check all the fields in the table, eg;
(this assumes you use odbc database, and the first field is where the username is stored) <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> while(odbc_fetch_row($cur)) { $tmp = odbc_result($cur,1) if ($tmp != $username) { $username_free = "FALSE"; break; } else { continue; } } $username_free = "TRUE"; [/code] This loops through the table, checking the 'username' field. If it doesn't find a match, it sets the variable as 'true', otherwise it returns a 'false'. |
|
#3
|
|||
|
|||
|
Okay.. that might look like what I'm looking for... Can I do that with MySQL?
Mike |
|
#4
|
|||
|
|||
|
EGADS! Don't do THAT!
If the desired username is in $username: $result=mysql_query("select count(*) from user_table where username='$username'"); if(mysql_num_rows($result)) { // username already used }else { // username available } |
|
#5
|
|||
|
|||
|
That wasn't what I was looking for, however, I think that does the job and I understand what I'm doing there more.
Appreciate the help from both of ya! Mike |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > checking for a value in a table |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|