Jump to content


Photo

vary basic form problem...


  • Please log in to reply
2 replies to this topic

#1 elias

elias
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationSpain

Posted 21 March 2006 - 08:25 PM

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:

                    <form action="test_print.php" method="post">

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

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

                     </form> 


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

And the result is a blank page.

Then I tried directly on the browser:

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

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




#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 21 March 2006 - 08:29 PM

Well first you are using a method of POST but trying to get the value with GET.

They need to match.

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

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

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

#3 elias

elias
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationSpain

Posted 21 March 2006 - 09:18 PM

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







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users