XpertWorlock Posted July 18, 2008 Share Posted July 18, 2008 I'm trying to get a log-in page that posts back to itself, currently it signs in okay, it just acts up if the user name hasn't been created yet. So how would I go about if the userName does not exist than to do something else. $userName = $_POST['userName']; $userPassword = $_POST['userPassword']; $result = mysql_query("SELECT * FROM users WHERE userName = '$userName'"); while($row = mysql_fetch_array($result)) { if ($userName != $row['userName']) {$_SESSION['userNotExist'] = "This user does not exist"; }; if ($userPassword != $row['password']) {$_SESSION['passwordIncorrect'] = "The password you have entered is incorrect"; }; Quote Link to comment https://forums.phpfreaks.com/topic/115417-solved-logging-in-problem/ Share on other sites More sharing options...
Xurion Posted July 18, 2008 Share Posted July 18, 2008 The thing you're doing wrong is you've made a while loop for something that should be returning one record. You should check to see if the query has returned any results, and if so, then check the password. $userName = $_POST['userName']; $userPassword = $_POST['userPassword']; $result = mysql_query("SELECT * FROM users WHERE userName = '$userName'"); $row = mysql_fetch_array($result) if(mysql_num_rows($result)==0){ $_SESSION['userNotExist'] = "This user does not exist"; }else{ if($userPassword != $row['password']){ $_SESSION['passwordIncorrect'] = "The password you have entered is incorrect"; } } Quote Link to comment https://forums.phpfreaks.com/topic/115417-solved-logging-in-problem/#findComment-593351 Share on other sites More sharing options...
XpertWorlock Posted July 18, 2008 Author Share Posted July 18, 2008 thank you, sometimes the answer is so simple Quote Link to comment https://forums.phpfreaks.com/topic/115417-solved-logging-in-problem/#findComment-593367 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.