subter Posted August 13, 2008 Share Posted August 13, 2008 I've tried to explain the problem to a few friends, but they don't seem to understand what I'm asking. I'll try to get my problem across the best I can. I've got a login form for the input of an email and password. After the form is submitted, I pass what was submitted to a variable and check the entries against an SQL table. If the login was a success, I redirect them to (just for example) 'loginsuccess.php', otherwise, they are redirected to 'loginfail.php'. Now, this is where the problem begins. After entering an incorrect email / password combination, I try to go back to the page where the form is. Since the PHP is on the same page as the form, it seems that what was entered into the form initially is sent through the PHP again when I attempt to go back to the login page, and, as a result, I am instantly redirected back to the 'loginfail.php' page. Is there any way to stop this from happening? I am very, very new to PHP, so please, be gentle. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/119572-solved-clear-data-after-failed-login-attempt/ Share on other sites More sharing options...
unkwntech Posted August 13, 2008 Share Posted August 13, 2008 I don't think the problem is with the PHP, please post the code so we can see what you are doing. don't forget to put it between [ php] and [/ php] when you post it. Link to comment https://forums.phpfreaks.com/topic/119572-solved-clear-data-after-failed-login-attempt/#findComment-616039 Share on other sites More sharing options...
subter Posted August 13, 2008 Author Share Posted August 13, 2008 I couldn't find a way to edit my initial post, but here's the PHP: <?php include('dbconnect.inc.php'); $valid = 1; $grabemail = $_POST['email']; $grabpassword = md5($_POST['password']); $grabemail = stripslashes($grabemail); $grabemail = mysql_real_escape_string($grabemail); $query = mysql_query("SELECT * FROM `clients` WHERE email='$grabemail' and password='$grabpassword'"); $count = mysql_num_rows($query); if($count == 1) { $valid = 0; print "1"; echo '<META HTTP-EQUIV="Refresh" Content="0; URL=loginsuccess.php">'; } if($valid == 1) { print "2"; echo '<META HTTP-EQUIV="Refresh" Content="0; URL=loginfail.php">'; } ?> Link to comment https://forums.phpfreaks.com/topic/119572-solved-clear-data-after-failed-login-attempt/#findComment-616054 Share on other sites More sharing options...
unkwntech Posted August 13, 2008 Share Posted August 13, 2008 You assigned valid as 1 so it will always be true. Link to comment https://forums.phpfreaks.com/topic/119572-solved-clear-data-after-failed-login-attempt/#findComment-616060 Share on other sites More sharing options...
subter Posted August 13, 2008 Author Share Posted August 13, 2008 Oh, and by the way, disregard the print "1"; and print "2"; Link to comment https://forums.phpfreaks.com/topic/119572-solved-clear-data-after-failed-login-attempt/#findComment-616061 Share on other sites More sharing options...
subter Posted August 13, 2008 Author Share Posted August 13, 2008 I've verified that the login works when the email and pass are correct. In the first if statement the value of $valid is set to 0, which makes the next if untrue. Link to comment https://forums.phpfreaks.com/topic/119572-solved-clear-data-after-failed-login-attempt/#findComment-616064 Share on other sites More sharing options...
subter Posted August 13, 2008 Author Share Posted August 13, 2008 I've solved this issue. I just removed the PHP from the page that the form was on, moved it to 'processlogin.php', and added action="processlogin.php" to the form. I was just searching for a way to solve this while keeping the PHP on the same page as the form. Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/119572-solved-clear-data-after-failed-login-attempt/#findComment-616078 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.