/    Sign up×
Community /Pin to ProfileBookmark

Trying to pass array variable to new page

I’m trying to pass an array of strings to a new page. On the new page when I try to retrieve the value of the array all it does is spell out Array. What is the problem?

The variable I’m trying to pass is $queries

[CODE]
echo”<br><br>Would you like to join this table with another?<br>
<form method = ‘post’ action = querymaker2.php>
<input type = radio name = rdo1 value = 1>yes
<input type = radio name = rdo1 value = 0>no
<input type = hidden name = queries value = ‘$queries’>
<input type = submit name = submit value = submit>
</form>”;
[/CODE]

and I’m retrieving it like this

[CODE]
while(list($key, $value) = each($HTTP_POST_VARS))
{
echo $value;
}
[/CODE]

And trust me I’ve tried it several different ways. It always returns the same value of Array

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@BeachSideJul 26.2005 — You got a bunch of incorrect stuff there...
[code=php]
echo"<br><br>Would you like to join this table with another?<br>
<form method = 'post' action = querymaker2.php>
<input type = radio name = rdo1 value = 1>yes
<input type = radio name = rdo1 value = 0>no
<input type = hidden name = queries value = '$queries'>
<input type = submit name = submit value = submit>
</form>";
[/code]

Should be...
[code=php]
echo'<br><br>Would you like to join this table with another?<br>
<form method="post" action="querymaker2.php">
<input type="radio" name="rdo1" value="1">yes
<input type="radio" name="rdo1" value="0">no
<input type="hidden" name="queries" value="' . $queries . '">
<input type="submit" name="submit" value="submit">
</form>';
[/code]
Copy linkTweet thisAlerts:
@CrushinauthorJul 26.2005 — Where do you find the protocol for this. I haven't used PHP in about 2 years and now I'm getting back to using it and a lot of small things have changed.
Copy linkTweet thisAlerts:
@NetNerd85Jul 26.2005 — www.php.net ? welcome back
Copy linkTweet thisAlerts:
@CrushinauthorJul 26.2005 — Those code changes didn't change anything.
Copy linkTweet thisAlerts:
@CompGeek01Jul 26.2005 — How I might do it:

[code=php]
<br><br>Would you like to join this table with another?<br>

<form method="POST" action="querymaker2.php">
<input type="radio" name="rdo1" value="1">yes
<input type="radio" name="rdo1" value="0">no
<input type="hidden" name="queries" value="<? echo $queries; ?>">
<input type="submit" name="submit" value="submit">
</form>[/code]


And then receive:

[code=php]
<?
foreach( $_POST as $value ) {
echo $value;
}
?>[/code]
Copy linkTweet thisAlerts:
@BeachSideJul 26.2005 — How I might do it:

[code=php]
<br><br>Would you like to join this table with another?<br>

<form method="POST" action="querymaker2.php">
<input type="radio" name="rdo1" value="1">yes
<input type="radio" name="rdo1" value="0">no
<input type="hidden" name="queries" value="<? echo $queries; ?>">
<input type="submit" name="submit" value="submit">
</form>[/code]


And then receive:

[code=php]
<?
foreach( $_POST as $value ) {
echo $value;
}
?>[/code]
[/QUOTE]


That is not how he had it though. He had it in an echo statement.

And the things I changed didn't have much to do with PHP as much as it had to do with proper HTML coding.

Also you must be more specific than [B]"Those code changes didn't change anything."[/B]

I am sorry but my telepathic powers are on the blink today... sunspots I believe is the cause ?
Copy linkTweet thisAlerts:
@CompGeek01Jul 26.2005 — If you can't copy and paste then I can't help you. I'm sorry if thats not how he had it...because it's "How I would do it".

Otherwise I wouldn't have put the disclaimer.
Copy linkTweet thisAlerts:
@bokehJul 26.2005 — while(list($key, $value) = each($HTTP_POST_VARS))

{

echo $value;

}

The above has nothing to do with the question but is an old PHP 3 construct and should work fine unless you have $HTTP_POST_VARS disabled in php.ini.

Now to your question which no one has answered yet.

Replace this line in your script:
[code=php]<input type="hidden" name="queries" value="<? echo $queries; ?>">[/code]

With this:
[code=php]<?php foreach($queries as $key => $value){print '<input type="hidden" name="queries['.$key.']" value="'.$value.'">'."n";}?>[/code]

Now after the form has been submitted $_POST['queries'] will be an array which is identical to your $queries array. Although this writes a hidden field for each key/value pair it will save any nonsense converting to and from a string.

Obviously the whole purpose of hidden data is to maintain an identical copy of the original data and that is exactly what this method does.
Copy linkTweet thisAlerts:
@NogDogJul 26.2005 — Another possibility: use a sessions and save the array to a $_SESSION variable.
Copy linkTweet thisAlerts:
@rch10007Jul 26.2005 — [code=php]
extract ( $_POST );
[/code]


http://www.php.net/manual/en/function.extract.php
×

Success!

Help @Crushin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...