Passing an entire array in PHP

Posted: 07-15-2003, 02:10 AM
Hi,

I saw a previous post about sending arrays but did not quite
understand the answers.

The problem is that I would like to pass an entire array as a hidden
input field from one php script to another. I've simplified the code
where form1.php calls form2.php when "Go" is hit:

form1.php
=========

<html>
<head>
<title>Form 1</title>
</head>
<body>
<h1>Form 1</h1>
<form action="form2.php" method=post>
<?
$record[0]="One";
$record[1]="Two";
printf("<input type=hidden name=\"record[]\" value=\"%s\">",$record);
?>
<input type=submit value="Go">
</form>
</body>
</html>

form2.php
=========
<html>
<head>
<title>Form 2</title>
</head>
<body>
<h1>Form 2</h1>
<?
$record=$_POST['record'];
printf("$record[0]=%s",$record[0]);
printf("$record[1]=%s",$record[1]);
?>
</body>
</html>

The result is:
Form 2
Array=Array=

How do I fix this?

Thanks in advance for any help.
Reply With Quote

Responses to "Passing an entire array in PHP"

Agelmar
Guest
Posts: n/a
 
Re: Passing an entire array in PHP
Posted: 07-15-2003, 02:49 AM
Phillip Wu wrote:
> Hi,
<snip>
rtfm
but in brief:
echo '<input type="hidden" name="myarray" value="',
base64_encode(serialize($myarray)),'">';

to get your array back:
$thearray = unserialize(base64_decode($_POST['myarray']));


Reply With Quote
Tony Marston
Guest
Posts: n/a
 
Re: Passing an entire array in PHP
Posted: 07-15-2003, 12:10 PM
If you want to pass an array from one PHP script to another then you
would be better off using sessions. The disadvantage of passing data
as hidden fields in your HTML form is that anybody can see it using
the browser's 'view source' option. It is even possible to change the
values before hitting the 'submit' button.

Learn how to use sessions. You won't be sorry you did.

Tony Marston


pwu@qantas.com.au (Phillip Wu) wrote in message news:<943cec75.0307141810.488a33d4@posting.google. com>...
> Hi,
>
> I saw a previous post about sending arrays but did not quite
> understand the answers.
>
> The problem is that I would like to pass an entire array as a hidden
> input field from one php script to another. I've simplified the code
> where form1.php calls form2.php when "Go" is hit:
>
> form1.php
> =========
>
> <html>
> <head>
> <title>Form 1</title>
> </head>
> <body>
> <h1>Form 1</h1>
> <form action="form2.php" method=post>
> <?
> $record[0]="One";
> $record[1]="Two";
> printf("<input type=hidden name=\"record[]\" value=\"%s\">",$record);
> ?>
> <input type=submit value="Go">
> </form>
> </body>
> </html>
>
> form2.php
> =========
> <html>
> <head>
> <title>Form 2</title>
> </head>
> <body>
> <h1>Form 2</h1>
> <?
> $record=$_POST['record'];
> printf("$record[0]=%s",$record[0]);
> printf("$record[1]=%s",$record[1]);
> ?>
> </body>
> </html>
>
> The result is:
> Form 2
> Array=Array=
>
> How do I fix this?
>
> Thanks in advance for any help.
Reply With Quote
 
LinkBack Thread Tools Search this Thread Display Modes
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Multi Dimension Array to CFC from Flash DaveHCYJ Coldfusion Flash Integration 1 08-01-2005 07:45 PM
simple question about passing array to document spar999 Macromedia Flex General Discussion 0 04-20-2005 01:05 PM
Passing value to Array pooknikk Macromedia Flash Data Integration 1 03-04-2005 01:11 PM
Dumping an entire array to the screen Ray at ASP 3 07-07-2003 05:28 PM
Passing an array from codebehind to vbscript Kevin Spencer ASP.NET General 0 06-27-2003 05:31 PM