Jump to content

Check Boxes, Loops and Databases


supanoob

Recommended Posts

Basically, what i want to do is update numerous database fields, if the checkbox linked to their ID is checked. if that makese sense?

 

I will have a page where multiple items will be shown, with a checkbox linked to them using a unique (auto_inc) ID, i then want to be able to select numerous items using the check box, and hit a validate button. I then want all the checked items to update in the database, i want the verified field to go from 0 to 1.

Link to comment
https://forums.phpfreaks.com/topic/200194-check-boxes-loops-and-databases/
Share on other sites

Something like this?

 

The fields in the form (method=post):

 

<input type="checkbox" name="user[]" value="1">
<input type="checkbox" name="user[]" value="2">

 

The php code to identify which users were checked:

 

if (is_array($_POST['user'])) {
  foreach($_POST['user'] as $id) {
    // $id contains the value of each checked box, process as you wish
  }
}

Thanks for sharing your thoughts. :)

 

But please only post in this forum if you have a PHP-related coding problem.

 

is this not php related? did i not ask for php help?

Something like this?

 

The fields in the form (method=post):

 

<input type="checkbox" name="user[]" value="1">
<input type="checkbox" name="user[]" value="2">

 

The php code to identify which users were checked:

 

if (is_array($_POST['user'])) {
  foreach($_POST['user'] as $id) {
    // $id contains the value of each checked box, process as you wish
  }
}

 

Thanks for ya help :) i will try that

 

Thanks for sharing your thoughts. :)

 

But please only post in this forum if you have a PHP-related coding problem.

 

is this not php related? did i not ask for php help?

You didn't ask for anything, other than if your request made sense. Other than that, you only told me what you wanted to do. You didn't ask a question related to PHP or specify what help you need help with. I mean, was there a problem with your code? Is it a logical issue and you don't know where to start?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.