473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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.
Jul 16 '05 #1
2 27627
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']));
Jul 16 '05 #2
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
pw*@qantas.com.au (Phillip Wu) wrote in message news:<94**************************@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.

Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bob | last post by:
When I try to pass an array to a class the program hangs up. php4, windows xp pro This debug is going real slow due to having to reboot after every test run. Any help would be greatly...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
8
by: Viator | last post by:
Hi All; I am working on project; where I need to call a DB2 stored procedure (also to be written in the project) which will update/insert some records in the database. The number of rows to be...
2
by: Newsgroup Posting ID | last post by:
i'm new to c and have gotten my program to run but by passing hardcoded array sizes through the routines, i want to make the array extendable by using realloc but i'd be doing it two routines down,...
13
by: monkeys paw | last post by:
I am passing an array to a function. My first attempt was like so: char *ary = {"an", "array"}; my_sort(ary); But that doesn't work because the function my_sort cannot determing the size of...
7
by: =?Utf-8?B?YmVyaWNr?= | last post by:
New to this, I used to pass an array like this function BytesToString(byref myarray() as byte, somethingelse as long) as long and m = BytesToString(fooBar(), bluenose) This would send...
10
by: joeSquid | last post by:
I am trying to write a C program that makes use of an array of structs, but I am having a problem passing the array as a parameter. The struct is an employee, defined in a header file as: ...
4
by: arnuld | last post by:
I am passing an array of struct to a function to print its value. First I am getting Segfaults and weired values. 2nd, is there any elegant way to do this ? /* Learning how to use an array...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.