close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

MySQLi Update form checkbox updating database with a value despite not being checked?

Thread began 10/01/2014 9:23 am by Nathon Jones Web Design | Last modified 10/02/2014 2:03 pm by Jason Byrnes | 5524 views | 15 replies |

Nathon Jones Web Design

MySQLi Update form checkbox updating database with a value despite not being checked?

I've got an update form that uses a checkbox to update a TINYINT field in a database table with either a Yes / 1 or No / 0 value.
However, even when the checkbox is left unchecked it still updates the TINYINT field with a 1?

This is the checkbox code:
<input name="SMTeventdel" type="checkbox" id="SMTeventdel" value="1" <?php if (!(strcmp(($rsEDITEVENT->getColumnVal("SMTeventdel")),1))) {echo "checked=\"checked\"";} ?>>

And this is the update code:
<?php
if (isset($_POST["formEDITEVENTBTN"]) || isset($_POST["formEDITEVENTBTN_x"])) {
$UpdateQuery = new WA_MySQLi_Query($SMTmysqli);
$UpdateQuery->Action = "update";
$UpdateQuery->Table = "SMTevents";
$UpdateQuery->bindColumn("SMTeventtitle", "s", "".((isset($_POST["SMTeventtitle"]))?$_POST["SMTeventtitle"]:"") ."", "WA_DEFAULT");
$UpdateQuery->bindColumn("SMTeventdesc", "s", "".((isset($_POST["SMTeventdesc"]))?$_POST["SMTeventdesc"]:"") ."", "WA_DEFAULT");
$UpdateQuery->bindColumn("SMTeventdate", "t", "".((isset($_POST["EDITEVENTPICKER"]))?$_POST["EDITEVENTPICKER"]:"") ."", "WA_DEFAULT");
$UpdateQuery->bindColumn("SMTeventtime", "s", "".((isset($_POST["SMTeventtime"]))?$_POST["SMTeventtime"]:"") ."", "WA_DEFAULT");
$UpdateQuery->bindColumn("SMTvenueID", "i", "".((isset($_POST["SMTeventvenue"]))?$_POST["SMTeventvenue"]:"") ."", "WA_DEFAULT");
$UpdateQuery->bindColumn("SMTeventimg", "s", "".$WA_DFP_UploadStatus["WA_UploadResult1"]["serverFileName"] ."", "WA_DEFAULT");
$UpdateQuery->bindColumn("SMTeventdel", "i", "".((isset($_POST["SMTeventdel"]))?$_POST["SMTeventdel"]:"") ."", "WA_DEFAULT");
$UpdateQuery->addFilter("SMTeventID", "=", "i", "".($rsEDITEVENT->getColumnVal("SMTeventID")) ."");
$UpdateQuery->execute();
$UpdateGoTo = "events.php";
if (function_exists("rel2abs")) $UpdateGoTo = $UpdateGoTo?rel2abs($UpdateGoTo,dirname(__FILE__)):"";
$UpdateQuery->redirect($UpdateGoTo);
}
?>

Page attached also. Thank you.
NJ

Sign in to reply to this post

Jason ByrnesWebAssist

you probably have an older copy of the webassist/mysqli/queryobj.php file on the server.

here is an updated one that should fix the problem

Attached Files
queryobj.php.zip
Sign in to reply to this post

Nathon Jones Web Design

I have a different UPDATE form that also has a checkbox and there is no difference in the pages. I attach that file, which works, so that you can compare it to the previous file which doesn't work.

I was therefore sceptical that it was anything to do with webassist/mysqli/queryobj.php which was confirmed when I uploaded the new file you've sent and the problem remained.

Would appreciate your help on this. Thank you.
NJ

Sign in to reply to this post

Jason ByrnesWebAssist

looks like the data type for the checkbox column is set ti integer in the insert behavior, you should use the Checkbox 1 /0 data type option instead.

Sign in to reply to this post

Nathon Jones Web Design

The database field is TINYINT and I have used the WebAssist MySQLi Update Record server behaviour to create the column bindings.
Why has the extension chosen the wrong type?

Also...

1) these are update forms not insert forms
2) Why is it working on gallery-edit.php and not edit-event.php? Both are set to the same thing and both are TINYINT fields in the database table.

Thank you.
NJ

Sign in to reply to this post

Jason ByrnesWebAssist

The extension is not choosing the wrong type, you are. when setting up the column bindings, you need to select the data type. The extension may preselect the integer data type since that is the data type in the database, but it has know way of knowing that the field feeding the data is a checkbox. in the case where you are using a checkbox, you need select to use the checkbox data type.

It shouldn't be working on the update page if you don't select to use the checkbox data type, so i really cant explain why it works there, but the long and short, regardless, is that you should be selecting the checkbox 1/0 data type in the insert and in the update behaviors when using a checkbox as the form element.

Sign in to reply to this post

Nathon Jones Web Design

I have done that, as advised, and it has not made any difference. Page attached.

Both tables have TINYINT fields which is what the checkboxes update. The page gallery-edit.php works and the page edit-event.php doesn't.

The only difference in the two pages is that in the Events table the TINYINT field has a default value of 1 whereas the Gallery table's TINYINT field has a default value of 0. This should have no bearing on the Update form though.

I have provided login details so you can see this happening online in the private message field below.

Thank you
NJ

Sign in to reply to this post

Jason ByrnesWebAssist

I'll need to troubleshoot directly, see the private message section.

Sign in to reply to this post

Nathon Jones Web Design

Below...

Sign in to reply to this post

Jason ByrnesWebAssist

i changed the default value setting instead of DB Default to WA_ZERO:

$UpdateQuery->bindColumn("SMTeventdel", "c", "".((isset($_POST["SMTeventdel"]))?$_POST["SMTeventdel"]:"") ."", "WA_ZERO");

The default value will be used when the checbox is unchecked and the checkbox value will be used when it is checked.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...