473,394 Members | 1,752 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,394 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 27632
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.