Checkboxes that are not checked do not appear in the $_POST array. See the code snippet...
Main Topics
Browse All TopicsI have a set of checkboxes (see screenshot) which provide the user with the ability to set the visibility of the related document in a listing elsewhere on the site. I have reviewed a number of the entries on EE that deal with multiple checkboxes but cannot quite get it to work. When the user changes the status of the checkbox(es) and the update button clicked, the checkbox values should be updated in the MySQL database and I'd like a bit of help with how the query loop should look, presumbly using 'foreach'. The bit of jQuery in the code is simply to control the enable/disable status of the submit button. All assistance much appreciated.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Your example looks more like this one (not a "delete" but similar, in that it uses an array for the checkboxes). I think your script needs to be aware of the checkboxes so it can test for and update the on and off conditions for each checkbox. Perhaps using a named element of the checkbox() array would be an easy way to go after this problem.
Best regards, ~Ray
I don't think the choice of iterator matters. The key here is knowing what checkboxes are expected and applying some predictable name to the checkboxes in the form script. Then in the action script, you also need to know what checkboxes are expected, so you can know that the ones which are omitted from the POST array are the ones that are "off".
Referring to the snippet posted above, at line 12 we produce an associative array of animals. This is the predictable set of names for the checkboxes. That array is available to both the action script and the form script. The action script processing is shown in lines 20~30. The form script is shown in lines 36~45.
You might want to install this code snippet and run it so you can watch the behavior. HTH, ~Ray
Yes, thanks I have tried the script and it works well. It's just that I cannot see how to incorporate it into my code. In my form script I show an array of checkboxes where the value is set as the check value (0 or 1) which is obviously incorrect so I have changed the value to the item ID (primary key). However, I can't see how to embed the principles of your code into it, and I am looking to update the database using a routine like the one below. Could you possibly incorporate the logic into the code I have posted?
"don't know how to get that out of the code above it."
What code "above it?"
Let me ask this again, "Please post the entire script" so we do not have to guess at the contents of undefined variables. Also, I would ask you to do two additional things to help debug this.
1. Turn on the error reporting by adding this to the top of the script:
error_reporting(E_ALL);
2. Use "echo" to print out the value of $query after it is prepared on line 40 and before it is used on line 41. Use var_dump() to print out the value of $result after line 41.
Thanks, ~Ray
It's best to use the code snippet for code - that way we can all see the same line numbers.
But I have to say, I do not think a 1,600+ line script is something to get debugged at EE. We can answer questions, and I have done that, showing you what must be done to identify checkboxes that are not checked. But for something of this size you should hire a software developer who can get paid for the time it is going to take to work through all of this.
best of luck with your project, ~Ray
I have no intention of having anything like the full page code debugged, it doesn't need it. 99% of the page works very nicely. I am simply having difficulty with getting the checkbox routine working and that's what I needed help with. I appreciate you taking the time to provide me with some snippets and I'll work at trying to integrate the principles you have shown. Thanks.
I have not managed to translate the code snippet based on a manual loop into my code. I am using Dreamweaver's repeat region behaviour for looping through the form and cannot work out how to tag the checkboxes both in terms of ID and 'checked' value. Once I get that sorted I know how to develop an appropriate MySQL update query. I do appreciate that experts do not always want merely to provide 'cut and paste' answers to problems but to help enquirers to think for themselves and that's good. Perhaps I need to go away and scratch my head a bit harder!
@kcalder: No disrespect meant, but I think you got a lot of effort out of EE over a 125 point question, and I wonder if you expected me to rework your code in order to get a grade of "A"? If so, you might want to review the grading guidelines before you exercise someone else on such a big task for so little reward.
Business Accounts
Answer for Membership
by: kcalderPosted on 2009-09-06 at 01:24:28ID: 25269122
Oops, just seen that I forgot to add the screenshot!
checkboxes