Ask a Question related to PHP Development, Design and Development.
-
Phillip Wu #1
Passing an entire array in PHP
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.
Phillip Wu Guest
-
Passing value to Array
If I've got x = "test5" How can I put the value of x to Array list=; I'd try to use ---> list= but is not work. -
passing array in the url
Hello there, I am unable to pass an array thought he url. Even the most simple array as in the code: $test = array(1,2,3,4); echo "<a... -
passing an array
Hello, what is the best way to pass an array to a sub routine, IE. my @fields = qw(one two three); send_array(@fields); -
Passing Array Via CGI.pm
Hello all, I'm a Perl newbie here and have a quick question regarding CGI.pm. I have a CGI script that passes an array to another CGI script as... -
Dumping an entire array to the screen
for iCounter = 0 to ubound(TheArray) response.write TheArray(iCounter) & "<br />" next Ray at work "Jacob" <yak2016@comcast.net> wrote in... -
Agelmar #2
Re: Passing an entire array in PHP
Phillip Wu wrote:
<snip>> Hi,
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']));
Agelmar Guest
-
Tony Marston #3
Re: Passing an entire array in PHP
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
[email]pwu@qantas.com.au[/email] (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.Tony Marston Guest



Reply With Quote

