PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Learning learning learning! Ok .. my index page I input the date through pulldowns. Once the submit is sent I go to antoher page to validate the date. Now, if there's an error I'd like it to be know and then redirect back to the index page.
<?php
$byear = $_POST['byear'];
$bday = $_POST['bday'];
$bmon = $_POST['bmonth'];
echo "byear = ".$byear."<br>";
echo "bday = ".$bday."<br>";
echo "bmon = ".$bmon."<br>";
if (checkdate( $bmon, $bday, $byear)) {
echo "Date is good!";
} else {
echo "Date is bad";
echo "Sending you back to do it again!";
header("Location: index.php");
}
?>
i get this error:
Warning: Cannot modify header information - headers already sent by (output started at C:\www\test.php:7) in C:\www\test.php on line 20
Interesting! So once this little bug is worked out when it hits a bad date it'll just shoot back to the index page. Is there a pause/timer/wait function in php? I didn't see one. I work with mainframe work flow and we have this function called wait. It'll wait for a file, wait for a number of seconds, wait for a user to OK it. Is there something similar?
Ok .. i got it .. I need to do all my checks at the beginning of the script and not as it flows down the page. Thanks for that link feyd. I really didn't need to get slammed with the RTFM comment. I think it was uncalled for! I did go to the doc about it, just that it didn't particularly make much sense to me.
After googling for awhile I found that I'd probably be better off testing it while on that page using a function.
I'm still putting this little tid bit of solatious info in my notebook!
Its all good. Just remember next time when you send any header, or cookie or session - that you cant have sent ANY text or white space to the user before hand. There is a good few posts a week on people asking why they get this error - so it gets a bit annoying after a while.