Cannot Redirect After Form Submission
I have a form on a HTML page that has form data, and would like to have the user redirected to a new URL page after they have pressed the submit button and it has emailed the infor
Solution 1:
To use the "header" function:
header("location: result.php");
You can't output/print/echo anything to the screen, so try this:
if ($_POST)
if ($result) header("location: result-page.php");
elseecho'Sorry, unexpected error. Please try again later';
Or you can use javascript to print the success msg and redirect:
if ($_POST)
if ($result) {
print "<script>alert('Ok, email sent');</script>";
print "<script>window.open('result-page.php','_self');</script>";
}else{
print 'Sorry, unexpected error. Please try again later';
}
Solution 2:
use the header('Location: $url);
snippet that your tried but correct the function to this:
header('Location: '.$URL);
just make sure the varibale $URL
is defined.
Post a Comment for "Cannot Redirect After Form Submission"