Handling chechboxes with more than one value

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
terry
Forum Newbie
Posts: 1
Joined: Mon Mar 09, 2009 2:19 am

Handling chechboxes with more than one value

Post by terry »

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
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);
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Handling chechboxes with more than one value

Post by requinix »

Code: Select all

$unit[]= $_POST['unit'];
You're adding the POST array as one value in the $unit array. You aren't combining the two, you're nesting them.

Code: Select all

$unit = $_POST['unit'];
You don't even need a $unit variable, really.
Post Reply