I was looking in stackoverflow, but i do not find exactly what I need. I need to insert checkboxes data sent with php into mysql like this 22111,22332,12123,121132.
I have this code (found here in the site)
<?php
foreach($_POST['idecod'] as $check) {
$sel = $check.',';}
$contenedor = "UPDATE inmdes SET idecod='$sel'";
$insertdb = mysql_query($contenedor) or die(mysql_error());
?>
Of course I have the checkboxes as an array:
<input name="idecod[]" type="checkbox" value="<?php echo $rs[0]; ?>" />
How can i insert multiple checkboxes like 2211223,2211223,1212233,12332122 or if is just one 222111222..???
And how can i retrive them as an array because i need to use something like this
<? php if (in_array('2211223', $idecod)) echo "checked"; ?>
To automatically check the previous checked boxes.!
Thanks in advance
Roberto
UPDATE
I have a list of options. These options act/des with checkboxes. I need to:
1.- Be able to register options checked (SOLVED thanks to @prodigitalso) 2.- Be able to automatically check the checkboxes previously checked.
So, I have the codes like this 221122,221133,225566,445522 in the table (mysql). I need the script to check what codes where previously checked (those that are in the table) and check them. For example:
I see the 5 options 221122,221133,225566,445522 and 663322. I check only 4 (221122,221133,225566,445522) and this is UPDATED in mysql database.
I come again to the options page. But previously i checked 221122,221133,225566,445522. So the script check EACH checkbox. So automatically check options 221122,221133,225566,445522 BUT it doesnt check 663322.
RS[0] is the code, for example 221122.