#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    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. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Ontario, Canada
    Posts
    498
    Rep Power
    18
    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'.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    Okay.. that might look like what I'm looking for... Can I do that with MySQL?

    Mike
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    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
    }
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    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

Similar Threads

  1. League table problem
    By silverduck in forum MySQL Help
    Replies: 8
    Last Post: February 10th, 2004, 01:38 PM
  2. Replies: 0
    Last Post: January 30th, 2004, 03:18 PM
  3. how to keep table on top, not centered??
    By vinyl in forum HTML Programming
    Replies: 2
    Last Post: January 20th, 2004, 07:19 PM
  4. DB design - flat files or in a table
    By persaltier in forum Database Management
    Replies: 1
    Last Post: December 12th, 2003, 09:39 PM
  5. Controlling Multiple table Heights in a Browser
    By AttaBoy in forum HTML Programming
    Replies: 1
    Last Post: December 10th, 2003, 05:24 AM

IMN logo majestic logo threadwatch logo seochat tools logo