Warning: Cannot modify header information [duplicate]
I know that this has been asked a thousand times and I still can't find mey error.
<body><?php
$con = mysql_connect("xxxxxxxxx","xxxxxxxxxxx","xxxxxxxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("xxxxxx开发者_开发问答xxxxx", $con);
$sql="INSERT INTO mytable (row1, row2)
VALUES
('$_POSTrow1]','$_POST[row2]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
header("Location: compsubmit.php}");
mysql_close($con)
?></body>
<body>
Thats the error. That is obviously an output.
You use the header() function. You can not send any output to the browser before using this function. And your <body>
is an output.
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
here <body>
is an error, but this error can also occur if the file encoding is UTF with BOM - the way to avoid is to encode it without BOM
add this code : ob_start();
at head of your file.. this would fix the problem...
when i got this problem many times.. adding ob_start()
cleared the probelm.
Might sound silly but have you used output buffering ?
精彩评论