Jump to content

Unwanted loop in a user validation form


jr_cumbo

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.