Thread: login screen

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

    Join Date
    Sep 2000
    Posts
    8
    Rep Power
    0
    Hi, I am trying to create a page where people type in login names, and passwords, then there is a processing page that checks to make sure that the password and login name are correct. I am having trouble with figuring out how to write my loop and if statment. Basically I am using a while loop and then an if statement. If anyone has any suggestions on the best way to do this it would be appreciated. Right now I seem to be having trouble holding the values that I am searching for so that I can compare them in the if statement. A BIG Thanks to anyone who helps.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    14
    Are you using MySQL to hold your user info?
    Can we see your code?

  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    8
    Rep Power
    0
    Yes I am using mysql.

    Here is my code... Thank you for helping me, I am just learning this.

    <?php
    include "connect.inc";

    $stmt = "SELECT name FROM klogin";

    $result = mysql_db_query("kmbdatabase",$stmt);
    while($row = mysql_fetch_object($result)){
    }

    if ($result == "Bob"){
    echo "You may pass";
    }else{
    echo "You are not in our database";
    }
    mysql_free_result($result);
    ?>
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    14
    I will assume you have a form which has a field for username and password and this gets submitted to the page with the following code(see my recommendation below that):
    <?php
    include "connect.inc";

    $stmt = "SELECT name FROM klogin";

    $result = mysql_db_query("kmbdatabase",$stmt);
    while($row = mysql_fetch_object($result)){
    }

    if ($result == "Bob"){
    echo "You may pass";
    }else{
    echo "You are not in our database";
    }
    mysql_free_result($result);
    ?>
    <?php
    include "connect.inc";

    //Change the field username to be whatever your field is and the variable $username to whatever you named the field in your form
    $stmt = "SELECT name FROM klogin where username = '$username'";

    $result = mysql_query($stmt);
    if (mysql_num_rows($result) > 0) {
    while($row = mysql_fetch_array($result)){
    if ($row["password"] == $password) {
    echo "You may pass";
    }
    else {
    echo "Wrong Password";
    }
    }
    }
    else {
    echo "You are not in our database";
    }

    mysql_free_result($result);
    ?>


  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    14
    Another thing you may consider expanding the login routine to set a cookie so that users don't have to login on every single protected page, nor would user/pw info have to be passed in the URL...
    http://www.devshed.com/Talk/Forums/F...ML/003177.html

    - MIke
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    14
    Well if you are gonna take it that far, you might as well use PHPLIB to take care of all of that for you.
  12. #7
  13. No Profile Picture
    Carpe Diem
    Guest
    Devshed Newbie (0 - 499 posts)
    I use some code included at the top of each page, its dead simple and if each user has a unique id you can reference other tables http://www.php4hosting.com/ir.phps



    ------------------

    Regards
    Darren
    --
    http://www.php4hosting.com/ $
    http://www.php4hosting.co.uk/
    PHP/MySQL Enabled Hosting/Dedicated Servers
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    8
    Rep Power
    0
    Thank you for your help. It was very useful.

Similar Threads

  1. Frames And Login Boxes ...
    By jammie in forum HTML Programming
    Replies: 4
    Last Post: February 17th, 2004, 12:38 PM
  2. Customizable XP login screen?
    By gman1001 in forum Windows Help
    Replies: 1
    Last Post: January 13th, 2004, 03:06 PM
  3. unique login, except registered
    By zbriu in forum MySQL Help
    Replies: 2
    Last Post: December 22nd, 2003, 04:47 AM
  4. Some help with screen please
    By JosephB in forum Linux Help
    Replies: 1
    Last Post: November 1st, 2003, 12:00 PM
  5. Right justify new window regardless of screen resolution
    By UncleMole in forum HTML Programming
    Replies: 4
    Last Post: August 19th, 2003, 06:08 PM

IMN logo majestic logo threadwatch logo seochat tools logo