vampke Posted February 27, 2007 Share Posted February 27, 2007 Hi guys, I'm trying to get this php-stuff to work. I actually wrote a working 'script' (yay for me)! In this script a value is calculated and according to this value, a message $msg is generated. This part works. Now I need to get this message to display on the next page. I'm sure this is extremely simple, but unfortunately I cannot get it to do this. After my script the thankyou url is called with these lines: header( "Location: $thankyouurl" ); exit ; How can I get the message $msg to display on the thank you url? Any pointers would be highly appreciated! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/40356-very-basic-php-question/ Share on other sites More sharing options...
boo_lolly Posted February 27, 2007 Share Posted February 27, 2007 you've got to be more specific. is there a form involved? what calculations are you running, and what is your $msg? Quote Link to comment https://forums.phpfreaks.com/topic/40356-very-basic-php-question/#findComment-195266 Share on other sites More sharing options...
New Coder Posted February 27, 2007 Share Posted February 27, 2007 I might be wrong put I'm sure you could pass the $msg variable through the url. This is fine as long as it isn't sensitive data. header( "Location: $thankyouurl?msg=$msg" ); exit ; And then use : $msg = $_GET['msg']; on the thank you page. hope this Helps Quote Link to comment https://forums.phpfreaks.com/topic/40356-very-basic-php-question/#findComment-195268 Share on other sites More sharing options...
magnetica Posted February 27, 2007 Share Posted February 27, 2007 Can I just say that after you call the: header("Location: $url"); AFter this line use the ob_end_flush; in order to free up memory and remove everything from the output buffer Quote Link to comment https://forums.phpfreaks.com/topic/40356-very-basic-php-question/#findComment-195271 Share on other sites More sharing options...
vampke Posted February 27, 2007 Author Share Posted February 27, 2007 @boo_lolly: yes there is a form involved: the user gives input and based on this the script does some basic math using the number selected from a list and multiply that by another number. resuls of this are put in the string $msg. All this works and I can e-mail the string $msg, but I can't seem to get it on the next page. @New Coder: thanks, but this does not seem to work I'm putting it on my page as <? $msg = $_GET['msg']; ?> is this correct? Quote Link to comment https://forums.phpfreaks.com/topic/40356-very-basic-php-question/#findComment-195276 Share on other sites More sharing options...
New Coder Posted February 27, 2007 Share Posted February 27, 2007 yes but you will need to then echo it <? $msg = $_GET['msg']; echo ($msg); ?> would be a way to check if you have passed it Quote Link to comment https://forums.phpfreaks.com/topic/40356-very-basic-php-question/#findComment-195281 Share on other sites More sharing options...
vampke Posted February 27, 2007 Author Share Posted February 27, 2007 hmmmm no luck the message in the url also seems to be blank: "thankyou.php?msg=" Quote Link to comment https://forums.phpfreaks.com/topic/40356-very-basic-php-question/#findComment-195287 Share on other sites More sharing options...
New Coder Posted February 27, 2007 Share Posted February 27, 2007 I would say its working on the pass but $msg is blank. test it by creating a variable on the first page eg $test = "hello"; Then header( "Location: $thankyouurl?test=$test" ); exit ; and finally on the thankyou page <? $test= $_GET['test']; echo ($test); ?> Quote Link to comment https://forums.phpfreaks.com/topic/40356-very-basic-php-question/#findComment-195289 Share on other sites More sharing options...
vampke Posted February 27, 2007 Author Share Posted February 27, 2007 this does seem to work, weird... maybe it is because $msg is too long? it consists of multiple lines, starting with "\n" I actually put it in a mail message a few lines above the header line, and there it works edit: ok, after removing the \n i get the first line of the $msg any way to get the rest of the message as well? Quote Link to comment https://forums.phpfreaks.com/topic/40356-very-basic-php-question/#findComment-195292 Share on other sites More sharing options...
New Coder Posted February 27, 2007 Share Posted February 27, 2007 Aah yes passing through the url you are probably restricted to 255 charaters I would look into cookies or breaking $msg down into smaller variables and then either still use cookies or post method to the next page Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/40356-very-basic-php-question/#findComment-195296 Share on other sites More sharing options...
boo_lolly Posted February 27, 2007 Share Posted February 27, 2007 i would not print the $msg in the url. i'd simply use a number identifier, and print the number in the url. for instance, if the calculation concludes one result, $msg = 1, another result, $msg = 2, and so on... then, on the page that is supposed to display the message, do something like this: <?php switch($_GET['msg']){ case 1: echo "message 1"; break; case 2: echo "message 2"; break; case 3: echo "message 3"; break; default: break; } ?> better yet, why do you have a header() function in your script? why don't you just use the form to action="your_page" and run the calculations on that page using the $_POST method, then, you wouldn't have to use header forwarding, you wouldn't have to print anything in the url, and your code would be much cleaner and efficient, and you could still use the switch statement. Quote Link to comment https://forums.phpfreaks.com/topic/40356-very-basic-php-question/#findComment-195306 Share on other sites More sharing options...
vampke Posted February 27, 2007 Author Share Posted February 27, 2007 i think i'll give your solution with a single php file a try tomorrow, I'll come back here with questions the first proposal you make is not possible: there are 1000 possible results thanks for helping out Quote Link to comment https://forums.phpfreaks.com/topic/40356-very-basic-php-question/#findComment-195349 Share on other sites More sharing options...
vampke Posted February 28, 2007 Author Share Posted February 28, 2007 okay people, could someone please point me in the right direction on how to get all the information in 1 file? Now I have an html file with a form that calls the php script: <form action="script.php" method="post"> How can I make sure that the message is printed in the original html file? Do I need to put the entire html code between <form> and </form> in the php-script that is called? How do I return a message after user clicks on 'post' button? I don't quite know where to start, so if someone could point me in the right direction? Quote Link to comment https://forums.phpfreaks.com/topic/40356-very-basic-php-question/#findComment-195927 Share on other sites More sharing options...
Yesideez Posted February 28, 2007 Share Posted February 28, 2007 Each parameter (ie. ?msg=) may not contain a value more than 100 characters. Quote Link to comment https://forums.phpfreaks.com/topic/40356-very-basic-php-question/#findComment-195954 Share on other sites More sharing options...
vampke Posted February 28, 2007 Author Share Posted February 28, 2007 you mean for use in the url? that is exactly what i am trying to avoid I actually solved things now, so everything is working, hurrah! I just used echo $msg, in stead of calling the thankyou url thanks to everybody that tried to help! Quote Link to comment https://forums.phpfreaks.com/topic/40356-very-basic-php-question/#findComment-195958 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.