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

    Join Date
    Jun 2000
    Location
    Canada
    Posts
    35
    Rep Power
    15
    I am having problems with an HTML form and PHP script...the HTML form if for people to register, and they have to enter a login and password. Of course I don't want 2 people to use the same login, so I wrote a PHP script to check in a MySQL database whether someone already registered under that username.
    I have problems with the following script:

    $login=="HTTP_POST_VARS[login]";
    $query="SELECT * FROM passwords WHERE login='$login'";
    $result=MYSQL_QUERY($query);
    IF ($row=mysql_fetch_array($result))
    {PRINT "<CENTER><P>Sorry, the user name $login has been taken. Please go back and enter a new user name</P></CENTER>";}


    This script doesn't work, meaning 2 people can still register under the same login...


    However, when I set up the variable $login, such as in the script below, the script works, meaning 2 people cannot register under the login 'john'...


    $login="john";
    $query="SELECT * FROM passwords WHERE login='$login'";
    $result=MYSQL_QUERY($query);
    IF ($row=mysql_fetch_array($result))
    {PRINT "<CENTER><P>Sorry, the user name $login has been taken. Please go back and enter a new user name</P></CENTER>";}


    the only difference between the 2 scripts is the "HTTP_POST_VARS" stuff...
    I have no idea why my first script does not work...Anyone???
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    $login=="HTTP_POST_VARS[login]";

    This won't work .becoz you will have to seperate your fieldname and value from HTTP_POST_VARS.See the manual for more details.



    here you can simply use your varibable name.


    eg:

    html portion:

    <form action="test.php" method="post">
    Login: <input type="text" name="login">
    </form>

    Now you can use your "$login" variable directly.

    ie,

    now the following will work fine..

    $query="SELECT * FROM passwords WHERE login='$login'";
    $result=MYSQL_QUERY($query);
    IF ($row=mysql_fetch_array($result))
    {PRINT "<CENTER><P>Sorry, the user name $login has been taken. Please go back and enter a new user name</P></CENTER>";}




    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    32
    Rep Power
    15
    I would code it as follows. If this doesn't work maybe you don't have track_vars enabled?

    if(@mysql_result(@mysql_query("select count(*) from passwords where login='$HTTP_POST_VARS[login]'"),0,0))echo("<CENTER><P>Sorry, the user name $HTTP_POST_VARS[login] has been taken. Please go back and enter a new user name</P></CENTER>");

Similar Threads

  1. UTF-8 problem in 4.1.1a
    By mehran20 in forum MySQL Help
    Replies: 1
    Last Post: February 8th, 2004, 02:21 PM
  2. fread problem: doesn t compile php code
    By ghorghor2002 in forum PHP Development
    Replies: 2
    Last Post: February 3rd, 2004, 05:25 AM
  3. Wierd problem inserting data with VB6
    By gregquinn in forum MySQL Help
    Replies: 5
    Last Post: February 2nd, 2004, 07:37 AM
  4. WinNT4 problem
    By sandipguha in forum Windows Help
    Replies: 0
    Last Post: January 27th, 2004, 02:06 AM
  5. Session Variable problem :(
    By modesty in forum PHP Development
    Replies: 1
    Last Post: January 15th, 2004, 04:00 AM

IMN logo majestic logo threadwatch logo seochat tools logo