Page 1 of 1

Html Check boxes and PHP

Posted: Mon Jul 28, 2003 1:07 pm
by DougieC
I am trying to make a form with multiple check boxes that can refine a mysql query search. When i try to pass it to the php script with a post, it only passes the last value checked. I'm new to all this so I am not even sure if I am doing it right :oops:
here is the html checkbox code
<input name="services" type="checkbox" value="*" checked>
<input name="services" type="checkbox" value="option1"> <input name="services" type="checkbox" value="option2"> <input name="services" type="checkbox" value="option3">

and the php
$services = $_POST['services'];
do i need to make $services an array, and if so would that be @services.

Thanks for the help

Posted: Mon Jul 28, 2003 1:10 pm
by m3rajk
i'm not sure if it's html or php here, but you're trying to pass a potential array, and arrays are signaled in php and most other scripting/programing languages i have encountered with [] at the end when you're talking about the array in general.

php is trying to use a string type. becasue of this, you only get the final value. this can be fixed by changing the name from services to services[]

however, this will ONLY give the checked values. be sure that's the functionality you want prior to using it. you may want a series of radio buttons instead.

Posted: Tue Jul 29, 2003 9:48 pm
by jmarcv
Yes, you need to make it an array, like so.

<input name="services[]" type="checkbox" value="*" checked>
<input name="services[]" type="checkbox" value="option1"> <input name="services[]" type="checkbox" value="option2"> <input name="services[]" type="checkbox" value="option3">