Cannot Post multiple checkbox reults using $_POST

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
malloy
Forum Newbie
Posts: 15
Joined: Fri Jun 01, 2007 2:02 am
Location: Melbourne, Australia

Cannot Post multiple checkbox reults using $_POST

Post by malloy »

Hi Everyone,

Im quite new to PHP, please excuse my use of terminology or lack of. I have created some 5 checkboxes and i trying to email the reults using the post command.

It works fine when i select one check box but when multiple checkboxes are slected only one is passed over.

the Post function im using is:
$headers .= "Prefered days of the week: " . $_POST["days"]. "\n";


The Checkbox code is:
<input type="checkbox" name="days" id="mon" value="Monday" /> Monday
<input type="checkbox" name="days" id="tue" value="Tuesday" /> Tuesday
<input type="checkbox" name="days" id="wed" value="Wednesday" /> Wednesday
<input type="checkbox" name="days" id="thu" value="Thursday" /> Thursday
<input type="checkbox" name="days" id="fri" value="Friday" /> Friday

Any assistance would be greatly appreciated.

Kind regards,

David
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

Code: Select all

<input type="checkbox" name="days[]" id="mon" value="Monday" /> Monday
<input type="checkbox" name="days[]" id="tue" value="Tuesday" /> Tuesday
<input type="checkbox" name="days[]" id="wed" value="Wednesday" /> Wednesday
<input type="checkbox" name="days[]" id="thu" value="Thursday" /> Thursday
<input type="checkbox" name="days[]" id="fri" value="Friday" /> Friday
malloy
Forum Newbie
Posts: 15
Joined: Fri Jun 01, 2007 2:02 am
Location: Melbourne, Australia

Post by malloy »

Thanks for your reply djot.
I tried your code but only the word 'Array' is passed when i add the brackets to the end of each of the 5 checkbox names.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

You'll need to convert the array to a string if you want to echo it. implode() or foreach() might be of interest.
Post Reply