Passing arrays

From: Date: Mon, 05 May 2003 21:57:59 +0000
Subject: Passing arrays
Groups: php.windows 
Request: Send a blank email to php-windows+get-19774@lists.php.net to get a copy of this message
Hello all.. I have a web form that requires users to check a checkbox next to Things To Do. Example: [] Ski [] Bike [] Read etc. The <input> for these is: <input type=\"checkbox\" name=\"mychoices[]\" value=\"ski\"> Ski <input type=\"checkbox\" name=\"mychoices[]\" value=\"bike\"> Bike <input type=\"checkbox\" name=\"mychoices[]\" value=\"read\"> Read When I submit the form, an array called $mychoices is created. Up until that point, everything works. I do a foreach() such as: foreach ($mychoices as $m) { echo "$m<br>"; } This displays the content of the array fine. What I want to do is display this array so that the user can review what he/she entered (such as above) and then click a submit button to actually send the data to a form that would enter the data into the database. The problem I'm having is sending the same array through another submit. The code I have for the second form is: echo " <form method=\"post\" action=\"submitchoices.php\"> <input type=\"hidden\" name=\"mychoices\" value=\"$mychoices\"> <input type=\"submit\" value=\"submit\"> </form> "; I get the following result: Warning: Invalid argument supplied for foreach() in e:\web\htdocs\maindesk\admin\deleteatt1.php on line 6 I can understand why I get this error because it's not sent as an array (name=\"mychoices\" and not name=\"mychoices[]\"). But when I do add the [] at the end of mychoices, it just ignores the array. I tried to be as clear as possible.. hopefully someone can help me. I think I could just recreate a new array while doing the foreach, but I'm wondering if there is a simpler way. Thanks, Metin Kale

« previous php.windows (#19774) next »