Form template: PHP line in <script> cause Warning: Cannot modify header. Possible solution -


i've few lines of script in head of file mixed php:

    <script>$( "#company" ).autocomplete({         source: "<?php echo  $absolute_site . "autocomplete/autocompletecompany.php" ?>".... ............. <script> 

later in file pass php command:

 header("location: index.php?act=edit&peopleid=$last_peopleid") 

but

warning: cannot modify header information - headers sent

and warning refers php line in script.

how without warning? thanks!

edit after reading how fix "headers sent" error in php question (and answers) , okneloper answer original question, modified title , propose solution i've used, in hope question not duplicate anymore , useful else has incurred in same problem.

solution

my form file included: php part

 if (isset ($_post["submit"]) ){             .... sql commands including the:            header("location:pathtopage") }  

and html form presentation:

<form> ...my form </form> 

problem because template file calling form file in in body, meaning after headers. avoid this, in form file, put form output in function.

 function output_form(){   <form> ...my form </form>        }  

in template file, first line included form file. later in body (where want print form) called form output function.

<?php include ('formfile.php'); /* no spaces before <!!!! */ ?> 

later in body

<?php form_output(); ?> 

hope can help!

you need either send headers before output or enable output buffering in top of script:

ob_start(); 

headers sent before body of response, if have started output of body, headers cannot changed or added.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -