Php Mysql Multiple Checkbox Update

  1. Mysql Update Multiple Fields
  2. Php Mysql Multiple Commands
  3. Php Mysql Update With Variable
  4. Php Mysql Multiple Layer Table Structure
  5. Php Mysql Multiple Queries

I have a table of languages from MySQL and in database there is a row 'enabled' that has values 1 or 0. 1 for enabled language, 0 for disabled. I would like to change those values with checkboxes i.

Active6 years, 2 months ago

I have a table called products, with an:

id: int, primary key, auto incrementproduct_name: varcharhighlighted: int (1 or 0)

So, I want the highlighted field to be totally updateable via my admin page, so whenever I get each product's (or row's) datas, I have a checkbox next to the product's name indicating if it's highlighted (1) or not (0).

This is my code:

For some reason, I'm getting the following error whenever I try to update the forms:

Thanks for your assistance in advance, I'm totally confused now, I've been struggling for hours now!

famefame

2 Answers

Change

to

isset() returns a boolean, and foreach expects an array.

Mysql Update Multiple Fields

Also you are prone to mysql injection.

blake305blake305
1,7292 gold badges19 silver badges49 bronze badges

additionaly to what blake305 said, you need to change this:

this will giv you an array in $_POST['checkBox']- unfortunately your id is gone then.

If thats necessary, you need to fetch every box explicitly:

Php mysql multiple update

Php Mysql Multiple Commands

name='checkBox_<?php echo $q['id']; ?>

Php Mysql Update With Variable

and don't use [] after the name since that has some meaning in PHP: the POST result will be an array instead of a string.

add: this looks weird as well: name='checkBox['; ?><?php echo $q['id']; ?><?php echo ']'>shouldn't that be name='checkBox[' . $q['id']. ']...

Axel AmthorAxel Amthor

Php Mysql Multiple Layer Table Structure

9,8321 gold badge18 silver badges41 bronze badges

Php Mysql Multiple Queries

Not the answer you're looking for? Browse other questions tagged phphtmlmysqldatabasecheckbox or ask your own question.