- Mysql Update Multiple Fields
- Php Mysql Multiple Commands
- Php Mysql Update With Variable
- Php Mysql Multiple Layer Table Structure
- 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.
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!
2 Answers
Change
to
isset() returns a boolean, and foreach
expects an array.
Mysql Update Multiple Fields
Also you are prone to mysql injection.
blake305blake305additionaly 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 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']. ']...