Jump to content


Photo

Need Help with my Login Script


  • Please log in to reply
4 replies to this topic

#1 unenergizer

unenergizer
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUSA

Posted 04 April 2006 - 06:43 PM

Ok.. Im teaching my self on how to make different things in php. Well, I am having trouble with my script and I have no clue where to start looking for errors...

<? //login.php
session_start();  // Start Session

include 'config.php';
include 'header.php';

$username = $_POST['username'];
$password = $_POST['password'];

mysql_query("SELECT * FROM user WHERE userid='$userid'");
$_SESSION['userid'] = $userid;

if((!$username) || (!$password)){
    echo "Please enter ALL of the information!<br />";
    include 'login_form.html';
    exit();
}

// Convert password to md5 hash
$password = md5($password);

$sql = mysql_query("SELECT * FROM user WHERE username='$username' AND password='$password' AND userlevel='$userlevel'");
$login_check = mysql_num_rows($sql);

if($login_check > 0){
    while($row = mysql_fetch_array($sql)){
    foreach( $row AS $key => $val ){
        $key = stripslashes( $val );
    }
        // Register some session variables!
        session_register('username');
        $_SESSION['username'] = $username;
        session_register('password');
        $_SESSION['password'] = $password;
        session_register('userlevel');
        $_SESSION['userlevel'] = $userlevel;

        mysql_query("UPDATE user SET last_login=now() WHERE userid='$userid'");

        header("Location: members.php");
    }
} else {
    echo "You could not be logged in! The username and password do not match! Please try again!<br />";
    include 'login_form.html';
}
?>

I know that I am asking help with something very simple, but I am learning. And any help as to why my script doesn't work would greatly help me understand what is going on.

Thanks!
unenergizer
[a href="http://www.gamehaxs.com" target="_blank"][/a]

#2 jvrothjr

jvrothjr
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts
  • LocationOhio

Posted 04 April 2006 - 07:12 PM

Session Start needs to be the first thing.

<? //login.php

session_start();

include 'config.php';


Start with that
If you understand everything you know nothing!

http://rcchjr.awardspace.com/

#3 unenergizer

unenergizer
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUSA

Posted 05 April 2006 - 05:38 PM

[!--quoteo(post=361668:date=Apr 4 2006, 02:12 PM:name=jvrothjr)--][div class=\'quotetop\']QUOTE(jvrothjr @ Apr 4 2006, 02:12 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Session Start needs to be the first thing.

<? //login.php

session_start();

include 'config.php';


Start with that
[/quote]

I know that... But everytime i try and log in, im getting my error message saying that the username and password is wrong. Did i write this incorrectly or something? Because im stupmted... There are not any syntax errors, I just cant log in. And all my myql tables names and everything else are 100% correct as i've looked those over time and time agin.....

Can anyone suggest or does anyone know what is wrong with my code???

thank you...
unenergizer
[a href="http://www.gamehaxs.com" target="_blank"][/a]

#4 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 05 April 2006 - 06:31 PM

Try getting the md5 of the password you are sending to the table and get what is stored in the table and double check to make sure they are the same thing. If you used different encryption then they are not going to match and your login will of course fail. Check that then you can worry about the code being wrong.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#5 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 05 April 2006 - 09:02 PM

i can't see you define $userid (first query) and $userlevel (second query) anywhere ?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users