I'm basically validating a form. If the inputs are invalid, i send the user back to main page(userpage.php). If everything is alright it send him to downoad page(download.php). I'm using header() for redirection. But i get the following error:
Warning: Cannot modify header information - headers already sent by (output started at public_html/validateinfo.php:8) in /public_html/validateinfo.php on line 94
Here is the code(validate.php)
<html>
<head>
<title>Validate</title>
</head>
<body>
<?php
$name = $POST['name_var'];
$address = $POST['address_var'];
$zipcode = $_POST['zipcode_var'];
$redirecturl = "download.php";
$userpage = "userpage.php";
$error=0;
if(!ereg("([a-zA-Z]+[[:space:]]?[a-zA-Z]+)+$",$name))
{
echo "Please input the name again!";
$error++;
}
if(!ereg("([a-zA-Z]+[[:space:]]?[a-zA-Z]+)+$",$address))
{
echo "Please input the address again!";
$error++;
}
if(!ereg("([0-9]{5})(-[0-9]{4})?$",$zipcode))
{
echo "Please input valid zipcode!";
$error++;
}
else //all input valid
{
$error = 0;
}
//redirecting here
if($error>0) //back to user page where he needs to fill the form again
{
header('Location: ' . $userpage); //
}
else //to another download page
{
header('Location: ' . $redirecturl);
}
?>
</body>
</html>
Thanks in advance