Jump to content

Archived

This topic is now archived and is closed to further replies.

elias

vary basic form problem...

Recommended Posts

Hi guys and gals

I am baffled by the inability to send variables accross two pages through a form...

This is a little experiment I set up to see exactly what was going on:

Form Page:

[code]
                    <form action="test_print.php" method="post">

                               <input type="text" name="site_id" value="something" size="30">

                    <input type="submit" value="Send">

                     </form>

[/code]

Print Page (test_print.php):
[code]
            $site_id = $_GET["site_id"];
            print "$site_id";
[/code]

And the result is a blank page.

Then I tried directly on the browser:

[code]http://www.domain.com/test_print.php?site_id=something[/code]

and that worked - I got the word "something" printed.

I have to add that I have moved server and all these pages worked before.

Also, someone has already suggested the use of $_GET["site_id"]; - which I dont know exactly what it does, but it does seem to make it work when variables are passed from one page to the other via the URL.

Can someone shed some light as to what is going on and how to fix it.

TIA

tahiche


Share this post


Link to post
Share on other sites
Well first you are using a method of POST but trying to get the value with GET.

They need to match.

this
[code]$site_id = $_GET["site_id"];
            print "$site_id";[/code]

Should be
[code]$site_id = $_POST["site_id"];
            print "$site_id";[/code]

Using method=GET in your form, you will see the values in the URL, that is why the page works when you put the value in the address. But in your form you are using method=POST, so in order to retrieve the variable on the next page you have to use the above code.


If the methog is POST then all variable references should be POST

Ray

Share this post


Link to post
Share on other sites
Hi Ray

Thanks a bunch for the explanation, I will do some further studying to make sure I undestand it thoroughly.

I just did not know where to turn.

Thanks again and have a good one!!

tahiche


Share this post


Link to post
Share on other sites

×

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.