pudge1 Posted August 4, 2010 Share Posted August 4, 2010 For some reason my LogIn script doesn't work. It connects to the database and everything alright but it doesn't work at all. I've checked the database multiple time and the information I am inputting IS in there. function Login($username,$password) { $user = '***'; $pass = '***'; $dbname = '***'; $connection = mysql_connect('localhost',$user,$pass); mysql_select_db($dbname, $connection); $sql = "SELECT Password FROM Users WHERE Username='$username'"; $query = mysql_query($sql , $connection); $arr = mysql_fetch_array($query); $a_password = $arr["Password"]; if($password == $a_password) { setcookie('LOGGED_IN','True_',time()+172800); setcookie('USERNAME',$username,time()+172800); } else { } } That is the function here it is in use: $username = mysql_real_escape_string( $_POST['username'] ); $password = mysql_real_escape_string( $_POST['password'] ); $username = strtolower($username); $password = strtolower($password); $username = md5($username); $password = md5($password); Login($username,$password); Quote Link to comment https://forums.phpfreaks.com/topic/209815-login-not-working/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2010 Share Posted August 4, 2010 What have you done to troubleshoot what it is doing? What does echoing both $password and $a_password show? Quote Link to comment https://forums.phpfreaks.com/topic/209815-login-not-working/#findComment-1095226 Share on other sites More sharing options...
pudge1 Posted August 4, 2010 Author Share Posted August 4, 2010 Password shows up what it should but $a_password is empty. Sorry I forgot to mention that. Quote Link to comment https://forums.phpfreaks.com/topic/209815-login-not-working/#findComment-1095315 Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2010 Share Posted August 4, 2010 Are your Username's actually stored using md5(), like you code implies they are? Quote Link to comment https://forums.phpfreaks.com/topic/209815-login-not-working/#findComment-1095330 Share on other sites More sharing options...
pudge1 Posted August 4, 2010 Author Share Posted August 4, 2010 Yeah I even compared the md5s of the data that was being put into LogIn() and they matched up exactly in the database. Quote Link to comment https://forums.phpfreaks.com/topic/209815-login-not-working/#findComment-1095332 Share on other sites More sharing options...
Pikachu2000 Posted August 4, 2010 Share Posted August 4, 2010 Send the query and the resulting array to the screen and see what you get. $sql = "SELECT Password FROM Users WHERE Username='$username'"; $query = mysql_query($sql , $connection); $arr = mysql_fetch_array($query); echo $sql . '<br /><pre>'; print_r($arr); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/209815-login-not-working/#findComment-1095360 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.