#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    15
    Rep Power
    0
    I need some help with the syntax here..
    I want it to do alil validation before the insert, but a query find that username is unique first.

    <?php
    mysql_connect (localhost, u , p);
    mysql_select_db (db);

    $result1 = mysql_query ("SELECT * FROM members WHERE username = '$username'");

    if ($row = mysql_fetch_array($result1))
    {
    print ("Error: The user name ");
    print ("$USER_NAME");
    print (" has been taken. Go back and enter a new user name.");
    print ("<p>");
    $verify = "bad";
    }
    elseif (eregi("[a-z]{2,16}", $firstname)
    &#0124; &#0124; eregi("[a-z]{2,25}", $lastname)
    &#0124; &#0124; eregi("[0-9a-z]{2,50}", $st1)
    &#0124; &#0124; eregi("[a-z]{2,25}", $city)
    &#0124; &#0124; eregi("[a-z]{2}", $st)
    &#0124; &#0124; eregi("[0-9]{5}", $zip)
    &#0124; &#0124; eregi("[0-9a-z]{6,16}", $username)
    &#0124; &#0124; eregi("[0-9a-z]{6,10}", $password))
    &#0124; &#0124; eregi("([_.0-9a-z-]+@)([0-9a-z][0-9a-z-]+.)+([a-z]{2,3})",$email)
    {
    mysql_query INSERT INTO members VALUES ('$firstname',
    '$lastname', '$st1', '$city', '$state', '$zip', '$username',
    '$password', '$email');
    print mysql_error();
    }else{
    print 'failed';
    }

    ?>

    Thanx
    Uga
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    You can try the following :


    $result=mysql_query ("SELECT * FROM members WHERE username = '$username'");

    if (mysql_num_rows[$result]==1){
    print "Username has been taken already";
    }else{

    $insertresult=mysql_query ("INSERT INTO members(firstname,
    lastname,st1,city,state,zip,username,password,email)VALUES ('$firstname','$lastname', '$st1', '$city', '$state', '$zip', '$username',
    '$password', '$email')");

    if (mysql_affected_rows($insertresult) == 1){

    print "Record has been addedn";

    }else{
    print "Error while inserting record";
    exit;
    }
    }


    ------------------
    SR -
    shiju.dreamcenter.net

    [This message has been edited by Shiju Rajan (edited May 06, 2000).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    15
    Rep Power
    0
    Thank you so much for a response, but will this also do the character validation that eregi would ?

    Thanx,
    Uga

Similar Threads

  1. help needed with syntax problem
    By flaminstar in forum MS SQL Development
    Replies: 1
    Last Post: February 12th, 2004, 10:37 AM
  2. sendmail installation problem on Linux
    By abuschr in forum Linux Help
    Replies: 0
    Last Post: January 14th, 2004, 10:08 AM
  3. removing openssl rh9
    By odave in forum Linux Help
    Replies: 0
    Last Post: January 11th, 2004, 11:51 PM
  4. IMAP Install issue
    By Sillysoft in forum Mail Server Help
    Replies: 5
    Last Post: December 11th, 2003, 02:52 AM
  5. PHP upgrade issues, plz help
    By justinm99 in forum PHP Development
    Replies: 1
    Last Post: October 23rd, 2003, 04:30 PM

IMN logo majestic logo threadwatch logo seochat tools logo