Save checkbox data per user


I come here in need of help.
I’v got this site set up witch check boxes with some products that it gets from the mysql database.
You can see the code below:


foreach($rows as $item): ?>

<?php endforeach; ?>
<input type=“checkbox” name="<?php echo $item->id."\" value=\"".$item->id; ?>" /> <?php echo $item->produkt_name; ?> info: <?php echo $item->info; ?>

I need to be able to save the “checked” check boxes on the users.
I’v got the login, logout and the database setup for the users.
But i am not sure how i am going to save the check boxes per user.
So that when they save it, they can log in later and retrieve the list of what boxes they checked and edit it if they want it.

Can any of you help me or point me in the right direction?

Best regards
Mr. Sorensen

Hi there,

Maybe in the users table you could have a field that stores the ids that they have checked (just like “135,297,656”). Then you can pull that into an array before you loop through the items with:
$chosen_item_ids = explode(",",$user->itemids);


foreach($rows as $item):
$checked = (in_array($item->id,$chosen_item_ids)) ? "checked=\"checked\"" : "";
                  <td><input type="checkbox" name="<?php echo $item->id."\" value=\"".$item->id; ?>"<?php echo $checked; ?> /></td>

Or something similar, depending on how you pull in user’s data (or not at all if you don’t like that idea!)

Hey guys, so i made myself a account, just to make it easy for myself.

Anyhow thanks Smokey PHP for the answer. I will take look at it and see what i can make out of it.

if anyone has a different solution, please do share

Sponsor our Newsletter | Privacy Policy | Terms of Service