moleyb Posted October 15, 2010 Share Posted October 15, 2010 Hi there, If anyone has a spare minute, id really appreciate someone casting their eye over this and seeing if there's anything obviously wrong. Writing to the txt file works fine, but the redirect to the thankyou.html page doesn't. Cheers Guys. <?PHP $filename = "output.txt"; #CHMOD to 666 $forward = 1; # redirect? 1 : yes || 0 : no $location = "thankyou.html"; #set page to redirect to, if 1 is above ## set time up ## $date = date ("l, F jS, Y"); $time = date ("h:i A"); ## mail message ## $msg = ""; foreach ($_POST as $key => $value) { $msg .= ucfirst ($key) .", ". $value . ", "; } $msg .= "\n"; $fp = fopen ($filename, "a"); # w = write to the file only, create file if it does not exist, discard existing contents if ($fp) { fwrite ($fp, $msg); fclose ($fp); } else { $forward = 2; } if ($forward == 1) { header ("Location:$location"); } else if ($forward == 0) { echo ("Thank you for submitting our form. We will get back to you as soon as possible."); } else { "Error processing form. Please contact the webmaster"; } ?> Many thanks, Mike Quote Link to comment https://forums.phpfreaks.com/topic/215952-php-write-to-txt-file-works-redirect-doesnt/ Share on other sites More sharing options...
premiso Posted October 15, 2010 Share Posted October 15, 2010 You need an echo statement here: else { echo "Error processing form. Please contact the webmaster"; } And you should call exit after the location call: if ($forward == 1) { header ("Location:$location"); exit; } Other then those two minor issues it looks fine. Quote Link to comment https://forums.phpfreaks.com/topic/215952-php-write-to-txt-file-works-redirect-doesnt/#findComment-1122525 Share on other sites More sharing options...
moleyb Posted October 15, 2010 Author Share Posted October 15, 2010 Thanks for taking a look Premiso, however, for some reason is still not redirecting.. (probably got something to do with it being Friday afternoon!) Quote Link to comment https://forums.phpfreaks.com/topic/215952-php-write-to-txt-file-works-redirect-doesnt/#findComment-1122527 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.