Handling chechboxes with more than one value
Posted: Mon Mar 09, 2009 3:24 am
Hi,
Please forgive me if the answer to my question is obvious:
My problem is related to list/explode (I think:-). In the html post array below, there is a sub-array (in red) with values from
checkboxes on the form page. Unfortunately, each checkbox passes two values on to the processing page, because the items in the list come from different tables and I have no guarantee that the ID-s are unique. The values are separated with ':' (colon). I know I could (an probably should:-) avoid this by designing my database differently..
I try to separate the values in the "unit" array back into two separate arrays for input to MySql, but it doesn't work. What am I doing wrong, and can anyone point me in the right direction?
Terry
Please forgive me if the answer to my question is obvious:
My problem is related to list/explode (I think:-). In the html post array below, there is a sub-array (in red) with values from
checkboxes on the form page. Unfortunately, each checkbox passes two values on to the processing page, because the items in the list come from different tables and I have no guarantee that the ID-s are unique. The values are separated with ':' (colon). I know I could (an probably should:-) avoid this by designing my database differently..
I try to separate the values in the "unit" array back into two separate arrays for input to MySql, but it doesn't work. What am I doing wrong, and can anyone point me in the right direction?
Terry
Here is the form input: <td><input type='checkbox' name='unit[]' value= '$serial:$tbid' />
And here is the post array:
array(9) {
["comment"]=>
string(7) "hey"
["stid"]=>
string(4) "6150"
["tuid"]=>
string(2) "40"
["day"]=>
string(2) "11"
["mth"]=>
string(1) "3"
["year"]=>
string(4) "2009"
["time"]=>
string(5) "17:30"
["submit"]=>
string(5) "Submit"
["unit"]=>
array(5) {
[0]=>
string(7) "13086:1"
[1]=>
string(14) "1881104443:2"
[2]=>
string(11) "6017573:2"
[3]=>
string(11) "6021552:2"
[4]=>
string(7) "F05:2"
}
}
And here is my list/explode:
$unit[]= $_POST['unit'];
foreach($unit as $uid) {
list($serial, $tbid) = explode(":", $uid);