Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

passing _GET values to _POST

0 views
Skip to first unread message

Mary Anderson

unread,
Jan 7, 2008, 8:20:51 PM1/7/08
to php-g...@lists.php.net
Hi all,

I have a screen get_collection.php which is supposed to be used to
select something called 'data sets'. My database (the postgres database
is not the problem, PHP is) has an entity called 'data series' which has
a child entity called 'data sets'. The user is first shown a list of
all the data series. He selects a subset and pushes a submit button.
The database supplies the names of the children of the selected data
series, which are then displayed in the scrolling list called 'data sets'.

My problem is getting the various screens in my application to talk
to each other. I have another screen called edit_reference.php which
is used to edit a reference with an id re_reference_id. Midway through
this screen I want to link the reference of re_reference_id to data
series and data sets chosen by the user by following a link from
edit_reference.php to get_collection.php.

I thought I could just give re_reference_id to get_collection as an
url variable. Unfortunately, this doesn't work. Pushing the submit
button to actually select the data series of interest causes the $_GET
to be forgotten. Printing the value of re_reference_id in a hidden
inpput field -- which I thought for sure would end up in the $_POST
array when I hit the get_data_series submit button doesn't work either.
Neither does just saying $_POST['re_reference_id'] = $re_reference_id.

Probably I should be using session variables here. But I think they
will have their own problems since they will be written on
edit_reference.php, remembered long after the call to get_collections,
and may cause trouble later.


My page is

http://www.demog.berkeley.edu/~maryfran/memdev/get_collection.php?re_reference_id=74

I am going to attach the php code and hope it makes it through.

Mary Anderson

Richard Lynch

unread,
Jan 7, 2008, 8:40:20 PM1/7/08
to Mary Anderson, php-g...@lists.php.net
On Mon, January 7, 2008 7:20 pm, Mary Anderson wrote:

EVERY http request is totally separate and independent of any other
http request, unless YOU specifically code something in the URL or
SESSION to tie them together.

> I thought I could just give re_reference_id to get_collection as
> an
> url variable.

You could, but it would have to be part of the ACTION="..." URL in
order to get passed on to the next HTTP request.

> Unfortunately, this doesn't work. Pushing the submit
> button to actually select the data series of interest causes the $_GET
> to be forgotten. Printing the value of re_reference_id in a hidden
> inpput field -- which I thought for sure would end up in the $_POST
> array when I hit the get_data_series submit button doesn't work
> either.

This should have worked.

Review it and see what is in $_POST with:
<?php var_dump($_POST);?>

> Neither does just saying $_POST['re_reference_id'] = $re_reference_id.

You can do that in the first script, but it won't affect the next one.

And it's probably a Bad Idea to cram things into $_POST or other
built-ins, as a matter of style.

> Probably I should be using session variables here. But I think
> they
> will have their own problems since they will be written on
> edit_reference.php, remembered long after the call to get_collections,
> and may cause trouble later.

You would have to be sure that you give meaninful shelf-life and names
to the data you choose to put in $_SESSION, and not twist yourself
into knots by snarling up your own data...

But it works a treat if you plan that part out.

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

Philip Thompson

unread,
Jan 8, 2008, 10:14:49 AM1/8/08
to php general

Richard had some good directions. I'll show you how to send a variable
via GET AND POST in this basic example (which has not been tested, but
should work)...

[Some HTML Page]
<html>
...
<form action="get_collection.php?re_reference_id_get=74" method="post">
<input type="hidden" name="re_reference_id_post" value="74" />
<input type="submit" value="Go get it!" />
<input type="hidden" name="submitted" value="1" />
</form>
...
</html>

[get_collection.php]
<?php
if (isset ($_POST['submitted'])) {
echo "POST: re_reference_id = ".
$_POST['re_reference_id_post']."<br/>";
echo "GET: re_reference_id = ".$_GET['re_reference_id_get'];
echo "<pre>";
print_r ($_POST);
print_r ($_GET);
echo "</pre>";
}
?>

If you tried this previously and it didn't work, then you may have
some bigger issues with the PHP installation. Otherwise, this *should*
work. Hope this helps!

~Philip

0 new messages