Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
  1. #1
    Junior Member BurgerBoy's Avatar
    Join Date
    Jun 2003
    Location
    New Zealand
    Posts
    8
    Member #
    1650
    Hey guys,

    I'm new around here. I'm having problems with a login page I made using PHP and MySQL.

    It won't log in for some reason. I think it has to do with the session, but am not sure.


    Heres a link to the page:
    www.dogbite.co.nz/login.php

    Username: admin
    Password: admin
    (dont worry, you cant gain access to anything with that username and password.)

    I'll be greatful for any help you guys can give me.

    Thanks :classic:

  2.  

  3. #2
    Junior Member BurgerBoy's Avatar
    Join Date
    Jun 2003
    Location
    New Zealand
    Posts
    8
    Member #
    1650
    Here's the code: (if it posts properly)

    PHP Code:
    <?php
    session_start
    ();

    if (
    $userid && $password)
    {
    // if the user has just tried to log in
    // mysql_select_db($database_connUsers, $connUsers);
    // $query = "select * from users where USERNAME='$userid' and USERPASS=password('$userpass')";
    // $result = mysql_query($query, $connUsers);
    // if (mysql_num_rows($result) >0 )

    $db_conn mysql_connect("localhost""*****""*****");
    mysql_select_db("*****"$db_conn);
    $query "select * from users where username='$userid' and userpass=password('$password')";
    $result mysql_query($query$db_conn);

    if (
    mysql_num_rows($result) >)

    {
    // if they are in the database register the user id
    $valid_user $userid;
    session_register("valid_user");
    }
    }
    ?>
    <html>
    <head>
    <title>Login</title>
    </head>

    <body>
    <font size="2" face="Verdana, Arial, Helvetica, sans-serif">
    <?php
    if (session_is_registered("valid_user"))
    {
    echo 
    "You are logged in as: $valid_user <br>";
    echo 
    "<a href=\"logout.php\">Log out</a><br>";
    }
    else
    {
    if (isset(
    $userid))
    {
    // if they've tried and failed to log in
    echo "Could not log you in";
    }
    else
    {
    // they have not tried to log in yet or have logged out
    echo "You are not logged in.<br>";
    }
    // provide form to log in
    echo "<form method=post action=\"login.php\">";
    echo 
    "<table>";
    echo 
    "<tr><td>Username:<br>";
    echo 
    "<input type=text name=userid></td></tr>";
    echo 
    "<tr><td>Password:<br>";
    echo 
    "<input type=password name=password></td></tr>";
    echo 
    "<tr><td align=center>";
    echo 
    "<input type=submit value=\"Log in\"></td></tr>";
    echo 
    "</table></form>";
    }
    ?>
    <?php 
    echo "$userid?>
    </font>
    </body>
    </html>

  4. #3
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    No offense but you desperately need to indent properly. Your code is pretty much unreadable...
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  5. #4
    Junior Member BurgerBoy's Avatar
    Join Date
    Jun 2003
    Location
    New Zealand
    Posts
    8
    Member #
    1650
    It is indented on my page. I can't help it if the forums won't post the code properly.

  6. #5
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    If it were indented on your page, and you copied it exactly, the indents would remain in the forums (unless you're saving the file as unicode)

  7. #6
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Unfortunately, I don't know enough about PHP sessions to offer any useful info regarding this. Sorry.

  8. #7
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    138 times
    This might help:
    A Complete, Secure User Login System
    http://phpbuilder.com/columns/tim20000505.php3

    I'm bookmarking this one!
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  9. #8
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    Looks like it should work...

    Can you give us error output? Which line it fails on at least.
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)

  10. #9
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    Try changing
    $query = "select * from users where username='$userid' and userpass=password('$password')";

    to

    $query = "select * from users where username=\"$userid\" and userpass=\"$password\"";

    I got it working, but reworked the page substantially, so that might be the only thing.
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)

  11. #10
    Junior Member BurgerBoy's Avatar
    Join Date
    Jun 2003
    Location
    New Zealand
    Posts
    8
    Member #
    1650
    Originally posted by james
    Try changing
    $query = "select * from users where username='$userid' and userpass=password('$password')";

    to

    $query = "select * from users where username=\"$userid\" and userpass=\"$password\"";

    I got it working, but reworked the page substantially, so that might be the only thing.
    Thanks man, I changed the code and it works perfectly now.


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:01 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com