Jump to content

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


Link to comment
https://forums.phpfreaks.com/topic/5441-vary-basic-form-problem/
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
Link to comment
https://forums.phpfreaks.com/topic/5441-vary-basic-form-problem/#findComment-19446
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.