how do I make this PHP code work properly (previous q deleted)?

$error needs to be declared globally, outside the 'if' statements. Each time, you are declaring $error inside the 'if' statements and each time the 'if' statement ends, the $error variable goes out of scope and deleted.
 
Hello,

I'm having trouble getting this piece of code to work properly it doesn't seem to be displaying any type of error message to the user and I'm not quite sure why - I'm no PHP expert so I have come to here for help, thanks.

= MAIN PHP CODE =
$submit = $_POST['submit'];

if (!(isset($_SESSION['password']) && $_SESSION['password'] != ''))
{

}
else
{
if($submit)
{
$query_check = mysql_query("SELECT * FROM `users` WHERE `password`='$password'");
$count_check = mysql_num_rows($query_check);
}

if($count_check != 0)
{
$error = 1;
}
else
{
$error = 0;

// Increase value of how many times logged in.
$query_logged = mysql_query("UPDATE `users` SET logged = logged+1 WHERE password='$password'");

// Log IP address for security purposes.
$query_ip = mysql_query("UPDATE `users` SET `ip_address`='$ip' WHERE password='$password'");

// Redirection to main page.
header("Location: area.php");
}
}

= ERROR CODE =
if($error==1)
{
$error2 = 0;
?>
<ul class="error">Incorrect password, please try again.</ul>
<?
}

if($error2==1)
{
$error = 0;
?>
<ul class="error">This account has been disabled.</ul>
<?
}
Thanks but nothings changed making the variables global.
It's a private login system to protect directories simple as, no account names just the password.

No complex user system with registration forms etc.
 
Back
Top