Jump to content

very basic php question


vampke

Recommended Posts

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!

Link to comment
Share on other sites

@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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.