unenergizer Posted April 4, 2006 Share Posted April 4, 2006 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.phpsession_start(); // Start Sessioninclude '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 Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted April 4, 2006 Share Posted April 4, 2006 Session Start needs to be the first thing.[code]<? //login.phpsession_start();include 'config.php';[/code]Start with that Quote Link to comment Share on other sites More sharing options...
unenergizer Posted April 5, 2006 Author Share Posted April 5, 2006 [!--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.phpsession_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 Quote Link to comment Share on other sites More sharing options...
txmedic03 Posted April 5, 2006 Share Posted April 5, 2006 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. Quote Link to comment Share on other sites More sharing options...
alpine Posted April 5, 2006 Share Posted April 5, 2006 i can't see you define $userid (first query) and $userlevel (second query) anywhere ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.