Jump to content

Need Help with my Login Script


unenergizer

Recommended Posts

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...

[code]<? //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';
}
?>[/code]

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
Link to comment
Share on other sites

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

[code]
<? //login.php

session_start();

include 'config.php';

[/code]

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.