I don't think I understand you correctly. All you want to do is check multiple checkboxes, put those checked values in a comma delimited string, and insert it in some table?
samaru
a.k.a inscissor
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18
Well, your problem seems to stem from how you're creating the checkboxes in the loop. First of all, here:
[php]
echo " ";
[/php]you don't create a name for the checkbox, so how are you going to retrieve it? The way it's usually done is you give the checkbox a name with open and closed bracks, like this: values[]
So when you pass this over, it'll pass it over as an array. So this is all you have to do:
[php]
<?php
$sql2 = "SELECT * FROM tbl_action";
$result = mysql_query($sql2);
while($act_row = mysql_fetch_array($result)) {
echo " ";
if(strstr($myrow['spy_action'], $act_row['action_id']))
echo "checked>";
echo ucwords($act_row['action_name'])."
";
}
?>
[/php]So when you submit this, it'll submit an array of the values of only the ones that got checked. So you loop through this array, in this case being values[]. Also, when you're retrieving this form variable, retrieve it as $_POST['values'] and not $_POST['values[]']. I'm sure you can do the rest. Anything else, let me know.
samaru
a.k.a inscissor
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18
Thanks Inscissor,
To be honest, I don't do much work with forms, which is why I wasn't sure how to handle this. I really appreciate the help, though.
Were you able to figure it out? I do this all the time, so it's no sweat. I'll give you code if you want.
samaru
a.k.a inscissor
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18
Given that the data is stored in an array, what type of structure should I use for storing it?
Didn't you say you wanted it in a comma delimited string? So your structure would be a string. All you would need to do is loop through the array, and as you're looping, append\concatenate the adjacent strings in the array. Fortunately, you could also use the implode() function, so you'll have something like this:
[php]
$values = $_POST['value']; // getting value array from form variable
$delimited_values = implode(",", $values);
echo $delimited_values;
[/php]
samaru
a.k.a inscissor
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18
That sounds fine. Maintaining it as an array gives you a lot of flexivity. You can manipulate it easily with the PHP array functions.
samaru
a.k.a inscissor
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18