berry05 Posted December 10, 2008 Share Posted December 10, 2008 i have the right username and the right two passwords and when i enter it to the fields and i submitit says login failed when its suppose to say login ok... any help? <?php $con = mysql_connect("localhost","root",""); if(!$con) die('Could not connect: ' . mysql_error()); mysql_select_db("register", $con); $username = (isset($_POST['username'])) ? mysql_real_escape_string($_POST['username']) : FALSE; $password1 = (isset($_POST['password1'])) ? $_POST['password1'] : FALSE; $password2 = (isset($_POST['password2'])) ? $_POST['password2'] : FALSE; if($_POST['submit']){ if(!$username) die('username not set'); if(!$password1) die('Password1 not set'); else $password1 = md5($password1); if(!$password2) die('Password2 not set'); else $password2 = md5($password2); $query = "SELECT username, id FROM users WHERE username='$username' AND password1='$password1' AND password2='$password2'"; $result = mysql_query($query) or die( mysql_error()); if($row = mysql_fetch_assoc($result)){ echo 'login ok'; } else { echo 'login failed'; } } else { ?> <html> <title>Login Page</title> <body> <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <label> Username: <input type="text" name="username" id="username"> </label> <p>Password1: <label> <input type="password" name="password1" id="password1"> </label> </p> <p>Password2: <label> <input type="password" name="password2" id="password2"> </label> </p> <p> <label> <input type="submit" name="submit" id="submit" value="Submit"> </label> </p> </form> </body> </html> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/136294-solved-login-script-help/ Share on other sites More sharing options...
phpSensei Posted December 10, 2008 Share Posted December 10, 2008 First print out $password1 and $password2 to see if it spits out any data. Link to comment https://forums.phpfreaks.com/topic/136294-solved-login-script-help/#findComment-711053 Share on other sites More sharing options...
dezkit Posted December 10, 2008 Share Posted December 10, 2008 change if($row = mysql_fetch_assoc($result)){ to if($row == mysql_fetch_assoc($result)){ Link to comment https://forums.phpfreaks.com/topic/136294-solved-login-script-help/#findComment-711054 Share on other sites More sharing options...
berry05 Posted December 10, 2008 Author Share Posted December 10, 2008 it worked! thank you! Link to comment https://forums.phpfreaks.com/topic/136294-solved-login-script-help/#findComment-711056 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.