Page 1 of 1
PHP Redirect
Posted: Mon Nov 14, 2011 1:27 pm
by mjstehn
I have a form that people fill out and then it calls a page where the data is processed and a confirmation page is displayed. This is a weekly submission, so what is happening is that users are coming to the page that processes the data because there browser remembers this page. I would like to check the $_POST variable and if blank direct them back to the entry form. Can anyone help me go about this? I have tried using header and put it before any data gets sent to the browser, but it does not seem to work. Thanks,
Re: PHP Redirect
Posted: Mon Nov 14, 2011 1:29 pm
by Celauran
Can you elaborate on what you've tried and what isn't working? What errors are you getting?
This should work fine:
Code: Select all
if (empty($_POST))
{
header("Location: whatever.php");
}
Re: PHP Redirect
Posted: Mon Nov 14, 2011 2:42 pm
by mjstehn
It just pulls the process data page with empty results. I even added an echo statement to make sure that the $_POST was empty and the that if condition is met. It is. It just does not re-direct. Where should I put this statement, before <html>? It is now after <title>. I would think there should be no issues with this working. Thanks for the help.
Mike
Re: PHP Redirect
Posted: Mon Nov 14, 2011 2:43 pm
by Celauran
It needs to be at the very top of the page, before any HTML.
Re: PHP Redirect
Posted: Mon Nov 14, 2011 2:59 pm
by mjstehn
Still does not work. Here is the code. The In If Statement comes up and then the rest of the page, it never points takes it to the other page. Any others suggestions?
<?php
if (empty($_POST))
{
echo "In If Statement";
header("Location: piksheet.htm");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Pick Submission</title>
Re: PHP Redirect
Posted: Mon Nov 14, 2011 3:03 pm
by Celauran
No error messages? Is error reporting on? I'd guess there's a "headers already sent" error being generated by not displayed.
Re: PHP Redirect
Posted: Mon Nov 14, 2011 3:22 pm
by mjstehn
Stupid mistake on my part. Forgot to take out my test echo statement. Once I took that out it worked. Thanks for all your help.
Mike