Ive tries to set a cookie like below:
<?php setcookie("cookiename",$managerid,time()+3600,"/");?>
However i keep getting this error when i upload it:
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/teamtactics.php:7) in /var/www/html/teamtactics.php on line 59
what causes this and how can i fix it
my code is below:
<?php
$managerid = $POST["managerid"];
$password = md5($POST["password"]);
$link = mysql_connect("localhost","username","password");
@mysql_select_db("databasename",$link);
$sql = "SELECT * FROM teaminfo WHERE teamid='$managerid'";
$result = mysql_query($sql);
$checkpassword = mysql_result($result,0,'password');
echo $checkpassword;
if ($checkpassword == $password) {
setcookie("cookiename",$managerid,time()+3600,"/"); ****THIS LINE CAUSES THE ERROR****
echo "<meta http-equiv='refresh' content='0,http://website.com/teamtactics.php'>";
} else {
echo "Sorry, the password you typed is incorrect for the Manager ID you entered (".$managerid."). Will return to the home page in 10 seconds";
echo "<meta http-equiv='refresh' content='10,http://website.com/index.html'>";
}
?>