I have a form on a page to submit a comment, and once a user places a comment I would like it to reload the page.
This is what I got
$insertGoTo = "employer.php?employer=" . $row_employer_page['employer'] . "";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
It works, however I got this error on submit.
Notice: Undefined variable: row_employer_page in /u/students/m/*******/public_html/cis231/project/employer.php on line 51
Warning: Cannot modify header information - headers already sent by (output started at /u/students/m/*******/public_html/cis231/project/employer.php:51) in /u/students/m/*******/public_html/cis231/project/employer.php on line 56
The lines it references are the code I posted above. I'm not sure what's going on, it reload the page how I want but throws that error
You can not send headers once you've echoed content already (at line 56). That header function. You may want to use a template engine though and echo the compiled template at the end of the file.
Another solution would be to capture the output with http://php.net/manual/de/function.ob-start.php and flush it afterwards.
On the top of your code:
<?php
ob_start();
?>