RE: [PHP-DB] Array as hidden input

From: Date: Thu, 28 Sep 2000 18:30:50 +0000
Subject: RE: [PHP-DB] Array as hidden input
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-3148@lists.php.net to get a copy of this message
> -----Original Message----- > From: hellekin@mmania.com [mailto:hellekin@mmania.com] > Sent: Thursday, September 28, 2000 11:54 AM > To: Mirko Nalesso > Cc: php-db@lists.php.net > Subject: Re: [PHP-DB] Array as hidden input > > > > I've a problem. Can an input hidden in a form be an array? Example: > > > > File prova.php > > > > <? > > $arr=array(); > > $arr[1]=11; > > $arr[2]=12; > > $arr[3]=13; > > ?> > > <form method="post" method="prova1.php"> > > <? echo "<input type=\"hidden\" name=\"arr\" > > value=\"$arr\">"; ?> > > <input type=submit value="NEXT" > > > <form> > > > > File prova1.php: > > > > <? > > echo"$arr[1] - $arr[2] - $arr[3]"; > > ?> > > > > On the Netscape, file prova1.php appears: > > > > r - r - a > > > > What's wrong? In a nutshell, you can't echo an array, even into the value attribute of an <input...> tag. You'll see the same thing if you just try echoing $arr to your page...all that'll come out is "array." > It seems that the value passed is the string "arr"... > > $arr[0] = a; > $arr[1] = r; > $arr[2] = r; > $arr[3] = a; > ... > > You should print an hidden entry for each value of $arr : *or* Have a look at serialize() (to convert an array into a single stream that can be passed as a form variable) and unserialize() (to convert that stream back into an array). http://www.php.net/manual/function.serialize.php http://www.php.net/manual/function.unserialize.php --- Mark Roedel | "Blessed is he who has learned to laugh Systems Programmer | at himself, for he shall never cease LeTourneau University | to be entertained." Longview, Texas, USA | -- John Powell

« previous php.db (#3148) next »