It doesn’t appear to be an issue. I actually got it to work finally. Instead of:
if (isset($_GET['variable_check ']) && ($_GET['variable_check '] == “1”)) { $query .= "variable_check = 1 "; } else { $query .= "variable_check = 0 "; }
I removed the == changed it to = it seemed to do the trick tho I’m not sure if it will have some reprecussions.
if (isset($_GET['variable_check ']) && ($_GET['variable_check '] = “1”)) { $query .= "variable_check = 1 "; } else { $query .= "variable_check = 0 "; }
I imagine it will.
Using a single = means you are no longer making a comparison, you are assigning a value, so is likely to return true no matter what making that part of the if condition virtually useless.
Took me forever to get the checkbox to work…
Besides all the mentioned spaces around keys the main thing I noticed was no matter what value you put for the checkbox value, when viewing the source it would always be empty. The value was being overwritten by the line below (line100) found on webapp.js.
Now if checkbox is checked the value 1 is saved to DB. If not checked, 0 is saved. You could probably reverse those values if you wanted zero saved when checked. At least I got it to work.
I’ve added a ‘Datetime’ field that pulls the correct date from the DB no problem but it won’t add it when putting in a new record or edit it, it just comes out as 0000-00-00 00:00:00 every time. I currently have the following code for it.
I had to add 2 more check boxes and a few other text fields. I found that if I add fields in the data.php query that are after the checkbox coding it makes the form bomb when submitted. Therefore I moved the variable_check coding to the end of the query and problem solved. However, now that I have to add 2 more check boxes (varchk_2, varchk_3) I can’t do them the same way as nothing seems to run after it gets to the first piece of checkbox code (variable_check). I apologize, I didn’t realize I needed more than one checkbox. Thanks.
First check is to see that you are adding commas into the query to separate the fields where you need to, and not adding them where you should not. Note that as long as the syntax is correct, it doesn’t matter what order you put the columns in the query.
See after the first checkbox, varchk_1, you have a comma (though only if you set it to 0, strangely). You need a comma between fields, so this would be correct:
varchk_1 = 0 , variable_check = 1
but this is not
varchk_1 = 1 variable_check = 1
So I would expect with that code, you’ll get a problem if the first one is set to 1. But either way, adding more check boxes would be just
Hello again,
Depending on the last working solution for you (by @droopsnoot ) and just for curiosity,
are you using (or planning to use) the values from these check boxes anywhere in your code/query?
in other words, can a checkbox have value other than 1 ?
if so, why not doing it as simple as this
If you just want to know whether or not a user ticked off a boxes regardless of its assigned value (toggling on/off true/false, Boolean like values), the code will be much shorter then
Currently it’ll just be used for 1 or 0 (checked or unchecked respectively) is there a benefit to doing it your way over droopsnoot’s or is it just a different way to go? Thanks.
First of, I have to mentions a typo I made in my previous post
I typed $GET instead of $_GET, so please make sure to change it before you test it
Now, Since it’s a 0/1 check only (where 1 means checked) then
there is no need to test your varchk# against (1) and you only check if the varchk# was sent (note that if a checkbox is not ticked off it will not be sent to the server),
also there will be no need to add value=“1” in your html code which makes you write a lesser html code
the php code also will be shorter and more reliable when building the sql query (by pushing column/value items to the chekArr then join them with the proper separator ", " so you don’t miss one or add extra one at the end of the query)