Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1

    Login Validation

    hey,

    ok heres my stituation:
    I have one page displaying two text boxes (password and username) thats ok, but on the next page how would i validate the username and password?

    BTW heres what the table looks like:

    id | username | password
    1 BD16088 <password>

  2. #2
    Join Date
    Aug 2002
    Location
    Long Island
    Posts
    427
    You would have to explain yourself better.

    What service scripting are you using? are you using an SQL database, flat text file, or a static user name/password?
    John Trovato
    In Office Networks, LLC
    Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.

  3. #3
    Join Date
    Jan 2003
    Location
    Perth, WA, Australia
    Posts
    1,276
    if you're using mysql, and you already know how to connect to the database, you could use:

    PHP Code:
    $q mysql_query("SELECT * FROM <tablename>");
    $d mysql_fetch_array($q);
    if ((
    $username == $d['username']) && ($password == $d['password'])) {
    echo(
    "Login Successfull");
    }
    else {
    echo(
    "Username or Password incorrect");

    nu-metal.org :: coming soon

  4. #4
    Join Date
    Mar 2003
    Location
    Manchester, England
    Posts
    8
    I don't code PHP so I'm just wondering about this...
    When testing for two conditions against two seperate arrays in a single if(), will it try to find $username in <array> then that part is true, then check if $password is in the next array? If so then you could match up the input username and the input password with person A's username and person B's password.

    Just wondering.

  5. #5
    Join Date
    Jan 2003
    Location
    Perth, WA, Australia
    Posts
    1,276
    uhm.... I can't understand what you're saying?

    $username will refer to the variable $username
    $var["username"] will refer to the "username" value in an array
    nu-metal.org :: coming soon

  6. #6
    when i go to http://www.gamenationx.com/MM/login.php and type in [username]revolverryan and [password]rmb1990 it works, but when i put in either
    [username]saveon and [password]12345 or
    [username]BlackDragon465 and [password]unknow
    it doesent work. heres the code for the first page:

    <html>

    <head>
    <base href="http://www.gamenationx.com/">
    <title>Members Sign in</title>
    </head>

    <body>
    Staff sign in:<br>
    <form method="post" action="/MM/page2.php">
    Staff Username <input type="text" size="30" name="loginid"><br>
    Password <input type="password" size="30" name="loginpword"><br>
    <input type="submit" size="30" value="Submit">
    </form>
    </body>

    </html>

    and here is the second page's coding :

    <?php

    $link_id = mysql_connect ("localhost", "gamenat_admin", "rmb1990") or
    die ('Cannot connect to the database.');

    mysql_select_db ("gamenat_everything");

    $q = mysql_query("SELECT * FROM users");
    $d = mysql_fetch_array($q);
    if (($loginid == $d['username']) && ($loginpword == $d['password'])) {
    echo("Login Successfull");
    }
    else {
    echo("Username or Password incorrect");
    }

    ?>

    also here is the table structure :

    users

    userid | username | password
    1 | revolverryan | rmb1990
    2 | BlackDragon465 | unknow
    3 | saveon | 12345


    thanks in advance

  7. #7
    Join Date
    Jan 2003
    Location
    Perth, WA, Australia
    Posts
    1,276
    ok, the code I gave you will only check it against the first row
    in the table. If you wanna check it against every row, use this:
    PHP Code:
    <?
    $link_id 
    mysql_connect("localhost","gamenat_admin","rmb1990")
    or die (
    'Cannot connect to the database.');
    mysql_select_db("gamenat_everything");
    $q mysql_query("SELECT * FROM users");

    // start loop
    while ($d mysql_fetch_array($q)) {
    if ((
    $loginid == $d['username']) && ($loginpword == $ ['password'])) {
    echo(
    "Login Successfull");
    }
    else {
    echo(
    "Username or Password incorrect");
    }
    }
    // end loop

    ?>
    I've commented the section where the loop is
    (it will loop through all of the rows in the table and check it against each one).
    I haven't tested this, but test it and tell me how it goes.
    nu-metal.org :: coming soon

  8. #8
    i got the error:
    Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /home/gamenat/public_html/MM/page2.php on line 9

  9. #9
    ok, i corrected the error but now it displays results for all three:

    Username or Password incorrectLogin SuccessfullUsername or Password incorrect

    what do i do now?

  10. #10
    Join Date
    Jan 2003
    Location
    Perth, WA, Australia
    Posts
    1,276
    PHP Code:
    <?
    $link_id 
    mysql_connect("localhost","gamenat_admin","rmb1990") or die("Cannot connect to the database.");
    mysql_select_db("gamenat_everything");
    $q mysql_query("SELECT * FROM users");
    $login false;
    while (
    $d mysql_fetch_array($q)) {
    if ((
    $loginid == $d["username"]) && ($loginpword == $ ["password"])) {
    $login true;
    exit;
    }
    }
    if (
    $login) {
    echo(
    "Login Successfull");
    }
    else {
    echo(
    "Username or Password incorrect");
    }
    ?>
    Last edited by digitok; 03-06-2003 at 11:06 PM.
    nu-metal.org :: coming soon

  11. #11
    Join Date
    Jan 2003
    Location
    Perth, WA, Australia
    Posts
    1,276
    Sorry for editing it about 100 times lol, that should work though
    nu-metal.org :: coming soon

  12. #12
    now, when it checks the first row it stops

    <?
    $link_id = mysql_connect("localhost","gamenat_admin","rmb1990") or die("Cannot connect to the database.");
    mysql_select_db("gamenat_everything");
    $q = mysql_query("SELECT * FROM users");
    while ($d = mysql_fetch_array($q)) {
    if (($loginid == $d["username"]) && ($loginpword == $d["password"])) {
    echo("Login Successfull");
    exit;

    }
    else {
    echo("Username or Password incorrect");
    exit;

    }
    }
    ?>

  13. #13
    Join Date
    Jan 2003
    Location
    Perth, WA, Australia
    Posts
    1,276
    Check my above post again, like I said I kept editing it
    nu-metal.org :: coming soon

  14. #14
    gives me a blank page

  15. #15
    Join Date
    Jan 2003
    Location
    Perth, WA, Australia
    Posts
    1,276
    hmm it looks fine to me lol can't see why it wouldn't work...

    just for fun, try changing

    if ($login) {

    to

    if ($login == "true") {

    it shouldn't make a difference but I really can't see anything wrong
    nu-metal.org :: coming soon

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •