Form not creating array properly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
goodwinpro
Forum Newbie
Posts: 9
Joined: Wed Mar 19, 2008 4:51 pm

Form not creating array properly

Post by goodwinpro »

This is a strange problem and I'm not sure where to look for the answer.

<form method="post" action="process.php">
<input type="checkbox" name="recid" value="44"/>
<input type="checkbox" name="recid" value="35"/>
<input type="checkbox" name="recid" value="25"/>
<input type="checkbox" name="recid" value="80"/>
</form>


I want to take this data and loop it.

My process page code is:

$data = array($_REQUEST['recid']);
foreach ($data as $val )
{
echo '<br> Data: '.$val.'<br>';
}


But my array only displays the last value (in this case 80). I can't get more than one value to display.

When I change method to GET I get:
?recid=44&recid=35&recid=25 on the URL. But still only get the last value to display.


Any ideas?
Thanks.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Form not creating array properly

Post by Christopher »

Code: Select all

<form method="post" action="process.php">
<input type="checkbox[]" name="recid" value="44"/>
<input type="checkbox[]" name="recid" value="35"/>
<input type="checkbox[]" name="recid" value="25"/>
<input type="checkbox[]" name="recid" value="80"/>
</form>
(#10850)
goodwinpro
Forum Newbie
Posts: 9
Joined: Wed Mar 19, 2008 4:51 pm

Re: Form not creating array properly

Post by goodwinpro »

Ok, tried this...

Code: Select all

<form method="post" action="untitled.php">
<input type="checkbox[]" name="recid" value="44"/>
<input type="checkbox[]" name="recid" value="35"/>
<input type="checkbox[]" name="recid" value="25"/>
<input type="checkbox[]" name="recid" value="80"/>
</form>
but it produced a bunch of text boxes on my form page and still only showed the last value. I wanted them as checkboxes. Am I missing something?
goodwinpro
Forum Newbie
Posts: 9
Joined: Wed Mar 19, 2008 4:51 pm

Re: Form not creating array properly

Post by goodwinpro »

Can anybody give me a working example that I can reference? I think I have it right, but I may have missed something.

Are there any settings in the PHP.ini file that affect how variables build arrays? I couldn't find any, but I'm not sure what to look for either.

Any ideas? This problem is really starting to hurt.

Thanks
Rob
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Form not creating array properly

Post by John Cartwright »

typo by arborint

Code: Select all

<form method="post" action="process.php">
  <input type="checkbox" name="recid[]" value="44"/>
  <input type="checkbox" name="recid[]" value="35"/>
  <input type="checkbox" name="recid[]" value="25"/>
  <input type="checkbox" name="recid[]" value="80"/>
</form>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Form not creating array properly

Post by Christopher »

Jcart wrote:typo by arborint
:mrgreen:
(#10850)
goodwinpro
Forum Newbie
Posts: 9
Joined: Wed Mar 19, 2008 4:51 pm

Re: Form not creating array properly

Post by goodwinpro »

BINGO! THANKS! That one worked.
Exactly what I was looking for.

I really appreciate the help. :D
Post Reply