Login Error

I have this problem at the moment, when im testing the register page everything works fine and the data ends up in the mysql database with the password encrypted. but when it coms to the login page no matter how i try to code it it always get my error or invalid user/name password.

Here in my login page.
[php]<?php include 'header.php'; ?>

 <>
<?php

echo ‘

Login


’;

if(isset($_SESSION[‘signed_in’]) && $_SESSION[‘signed_in’] == true)
{
echo ‘You are already signed in, you can sign out if you want.’;
}
else
{
if($_SERVER[‘REQUEST_METHOD’] != ‘POST’)
{
echo ’
Username:

Password:


';
}
else
{

	$errors = array(); 
	
	if(!isset($_POST['user_name']))
	{
		$errors[] = 'The username field must not be empty.';
	}
	
	if(!isset($_POST['user_pass']))
	{
		$errors[] = 'The password field must not be empty.';
	}
	
	if(!empty($errors)) 
	{
		echo 'A couple of fields are not filled in correctly..<br /><br />';
		echo '<ul>';
		foreach($errors as $key => $value) 
		{
			echo '<li>' . $value . '</li>'; 
		}
		echo '</ul>';
	}
	else
	{
		$sql = "SELECT 
					user_id,
					user_name,
					user_level
				FROM
					users
				WHERE
					user_name = '" . mysql_real_escape_string($_POST['user_name']) . "'
				AND
					user_pass = '" . sha1($_POST['user_pass']) . "'";
					
		$result = mysql_query($sql);
		if(!$result)
		{
		
			echo 'Something went wrong while signing in. Please try again later.';
			
		}
		else
		{
			
			if(mysql_num_rows($result) == 0)
			{
				echo 'You have supplied a wrong user/password combination. Please try again.';
			}
			else
			{
				
				$_SESSION['signed_in'] = true;
				
				while($row = mysql_fetch_assoc($result))
				{
					$_SESSION['user_id'] 	= $row['user_id'];
					$_SESSION['user_name'] 	= $row['user_name'];
					$_SESSION['user_level'] = $row['user_level'];
				}
				
				echo 'Welcome, ' . $_SESSION['user_name'] . '. <br /><a href="index.php">Continue to find your new club</a>.';
			}
		}
	}
}

}

?>
<>

<?php include 'footer.php'; ?>[/php]

Any help would be great,
thanks.

have you tried checking for any php errors? like so…

$result = mysql_query($sql) or die(mysql_error());

This may display any error you have in database?

Just a thought.

Sponsor our Newsletter | Privacy Policy | Terms of Service