hi,
i have a login form that searches a mysql database for the user and checks that the password is correct. it then redirects to the main page, the problem is i want to set a cookie containing the username.
this is the code:
<?php setcookie("user","$username");
if((!$username) or (!$password))
{header("location:error1.php"); exit();}
$conn=@mysql_connect("localhost","admin","admin")
or die ("connection");
$rs=@mysql_select_db("user",$conn)
or die ("db selection");
$sql="select * from auth where username=(\"$username\") and password=(\"$password\")";
$rs=mysql_query($sql,$conn)
or die ("query");
$num=mysql_numrows($rs);
if($num !=0)
{header("location:logged.php"); exit();}
else
{header("location:error2.php");}
?>
if i do it this way it , it does not set the cookie.
ive tried seperating the cookie of
<? setcookie ("user","$usename"); ?>
<? .....rest of code...... ?>
but it comes up with the error "headers already sent"!!
Please help