jr_cumbo Posted July 18, 2008 Share Posted July 18, 2008 Hi all, I'm having trouble with a user validation form Here are the to scripts that I think are causing the problem: The loginform.php <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>HTF User Login</title> <link href="../mm_hft.css" rel="stylesheet" type="text/css" /> </head> <body> <?php require_once('../Connections/HTFConnection.php'); //This script works fine require_once ('../Connections/checktext.php'); //This script works fine require_once ('../Connections/authencation.php'); // ***** I think is script might be the cause ***** ?> <form id="loginform" name="loginform" action="<?php echo $loginFormAction; ?>" method="post"> <p>User Login</p> <?php $user=$_POST['loginuser']; $count = mysql_num_rows(mysql_query("SELECT user_name FROM user_signup WHERE user_name='".$user."'")); if (isset($_POST['loginsubmit'])) if ($count == 0) { echo "<p><font color=red>Username and Password Not Found</font></p>"; } ?> <table width="267" border="0"> <tr> <td width="83">User Name:</td> <td width="168"> <label> <input type="text" name="loginuser" id="loginuser"/> </label> </td> </tr> <tr> <td>Password:</td> <td> <label> <input type="password" name="loginpasswd" id="loginpasswd" /> </label></td> </tr> </table> <p> <label> <input type="submit" name="loginsubmit" id="loginsubmit" value="Submit" /> </label> </p> </form> </body> </html> The authencation.php <?php // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['loginuser'])) { $loginUsername=$_POST['loginuser']; $password=$_POST['loginpasswd']; $redirectLoginSuccess = "../index.php"; $redirectLoginFailed = "login.php"; mysql_select_db($database_HTFConnection, $HTFConnection); $LoginRS__query=sprintf("SELECT user_name, user_passwd FROM user_signup WHERE user_name=%s AND user_passwd=md5(%s)", // *** Function to add '' to the username and password, Example 'user' and 'password' GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $HTFConnection) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { // *** declare a session variables and assign them $_SESSION['Username'] = $loginUsername; if (isset($_SESSION['PrevUrl']) && false) { $redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $redirectLoginSuccess ); } else { header("Location: ". $redirectLoginFailed ); } } ?> I'm using eclipse to debug the problem and it seems when the user enters a valid username and password the script works fine redirects them to the correct page. The problem is when the user enters a invalid username and password it seems that the script will loop though the code twice, the first time it goes though the code it sets the var $count to 0, but the second time it goes though the code it sets $count to false meaning it will not echo the error message. I'm using Windows with PHP Version 5.2.4 Any Help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/115360-unwanted-loop-in-a-user-validation-form/ Share on other sites More sharing options...
unkwntech Posted July 18, 2008 Share Posted July 18, 2008 Try adding exit; after else { header("Location: ". $redirectLoginFailed ); } and see what happens. Link to comment https://forums.phpfreaks.com/topic/115360-unwanted-loop-in-a-user-validation-form/#findComment-593097 Share on other sites More sharing options...
jr_cumbo Posted July 18, 2008 Author Share Posted July 18, 2008 I was thinking that too I have put exit; in a few places where I think it might work, but for some reason it will not drop out it will just continue a second time around. Link to comment https://forums.phpfreaks.com/topic/115360-unwanted-loop-in-a-user-validation-form/#findComment-593102 Share on other sites More sharing options...
samshel Posted July 18, 2008 Share Posted July 18, 2008 on failure you are redirecting to login.php, where as index.php is one level up..you sure about the login.php path? try giving full URL, just to debug thats not causing the problem. Link to comment https://forums.phpfreaks.com/topic/115360-unwanted-loop-in-a-user-validation-form/#findComment-593128 Share on other sites More sharing options...
jr_cumbo Posted July 18, 2008 Author Share Posted July 18, 2008 No that's not the problem it redirect fine on failure, it just does not echo the error message when I need it too. Its only displaying the login.php page without the echo message when no user is found. Link to comment https://forums.phpfreaks.com/topic/115360-unwanted-loop-in-a-user-validation-form/#findComment-593130 Share on other sites More sharing options...
samshel Posted July 18, 2008 Share Posted July 18, 2008 sorry i am slightly confused.. the code for showing error is on "loginform.php", you are redirecting to "login.php" and you are expecting to see the error there? Sorry if i got it terribly wrong. Link to comment https://forums.phpfreaks.com/topic/115360-unwanted-loop-in-a-user-validation-form/#findComment-593134 Share on other sites More sharing options...
jr_cumbo Posted July 18, 2008 Author Share Posted July 18, 2008 No my fault, I see how I have confused you loginform.php and login.php are the same srcipt I accidentally named the login.php script, loginform.php on the first post. Got confused with another project I'm working on. Sorry Link to comment https://forums.phpfreaks.com/topic/115360-unwanted-loop-in-a-user-validation-form/#findComment-593135 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.