I am trying to make where you can not login once you are already logged in. this what i have and i dont get an error but it still lets them login again. if anyone can tell my why its letting them login twice that would be great. thanks
<?php
setcookie("c_user", "$username");
setcookie("c_pass", "$password");
?>
<html>
<head>
<title>Login</title>
<link rel="stylesheet" type="text/css" href="eg.css" />
</head>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("register",$db);
$login = "SELECT username,password FROM members WHERE username = '$c_user' AND password = '$c_pass'";
$result = mysql_query($login);
if (mysql_num_rows($result) > 0)
{
echo "You are already Logged in.";
}
else
{
if($submit)
{
$db = mysql_connect("localhost", "root");
mysql_select_db("register",$db);
$user = "SELECT username,password FROM members WHERE username = '$username' AND password =
'$password'";
$result = mysql_query($user);
if (mysql_num_rows($result) > 0)
{
echo "Welcome $username.<a href='members.php'>here</a>";
}
else
{
echo "Please try again.<a href='login.php'>Click here to login in again.</a>";
}
}
else
{
?>
<form method="get" action="<?php echo $PHP_SELF ?>" target="body">
<h3>Username:</h3><input type="Text" name="username">
<h3>Password:</h3><input type="password" name="password">
<input type="submit" name="submit" value="submit">
<?php
}
}
?>
</body>
</html>
[code=php]