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 whichi added and my code is <?php $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>"; } please please help me out my final project is due on 27 i m stucked on this from last 2 days
<?php ob_start(); $_POST = array_map('mysql_real_escape_string', $_POST); $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>"; } ob_flush(); ?> PHP:
i have applied the code which u modified it still gives me same error Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\widget_corp\create_subject.php:1) in C:\xampp\htdocs\widget_corp\create_subject.php on line 15 but the there is something change in this warning C:\xampp\htdocs\widget_corp\create_subject.php:1) it was connection.php when i run my code kindly telll me solutions please i beg you guys
In order to use header() it needs to be at the very top of the page before anything else on the page is output (ie. it needs to be before <html> and nothing else can be output to the page before it). If that is at the very top of your page make sure nothing else is outputting code. The 'exit' line is most definitely not required.
i have found out problem i checked it on other machine and use some other editor it works there i m using xampp apache server and my sql i showed this problem to my teacher too he was in hurry he said you php settings is not configured so can i guess there is problem about my configuration but thanks to all you guys you guys really helped me i m thank ful too all of you for eternity thanks a lot hope u will keep help me like this and make me a good programmer likes you guys well i posted this problem on other website too then a professor of university of California david jhon said your header in configuration is automatic go to php setting and disable it then this will work on your machine so this is why i was asking about how to configure or change setting otherwise i am still having problem thanks alot agian and one more thank anyone can help to tell how to change settings in php confrigration ? or chat should be the default php settings in xammp?
No need to be at the top of the page but before any output, that's why it's header, for it sends HTTP headers, before the actual output.
well i m new learner of php i dnt know how to send http header could you write that syxtax? please i have written my code aboce could you cpo it and paste it with your syntax if you could do this please i will be thankful to you for eternity i am stucked for last 4 days
check for spaces on all syntaxes above header() function.. make sure remove all spaces.. nvm the next lines.