Page 1 of 1

php header problem

Posted: Sat Feb 20, 2010 6:42 pm
by azeem12
i m having problem in redirecting im making content management system
i get a post values from form which contain subject name ,position,visible and then insert as an new row value is inserted correctly but i want to redirect to content.php page from create_subject.php back to my content.php when i use header("Location: content.php");
it gives me this error when i fill form and hit submit error is "Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\widget_corp\includes\connection.php:1) in C:\xampp\htdocs\widget_corp\create_subject.php on line 14" then when i again open content.php then it sucessfully show the new entry which i added my code is

Code: Select all

$menu_name= $_POST['menu_name'];
$position = $_POST['position'];
$visible = $_POST['visible'];
 
$query = "INSERT INTO subjects (
menu_name, position, visible)
Values ( '{$menu_name}',{$position},{$visible})";
if(mysql_query($query,$connection)){
header("Location: content.php");
exit;
}else {
echo "<p> Subject creation is failed .</p>";
echo "<p>".mysql_error()."</p>";
}

help me pleaseeeeeeeeee i m stucked from last 2 days

Re: php header problem

Posted: Sat Feb 20, 2010 9:02 pm
by califdon
Although you haven't shown the first part of the code, no doubt it either has an HTML header (like <!DOCTYPE....> or <HTML> or even a blank line at the top). That's what the error message is telling you. You can't send ANY kind of a header to the browser and then try to send a PHP header. You can only send a PHP header as the very first thing that is sent to the browser.