Boolean insert

Hi,
think I am being really thick this morning but cannot get a boolean to insert or update.

PHP/Mysql.

I have a field in the DB that is a boolean. I have a form with a tickbox, value 1 for ticked, 0 for unticked.

Field on DB is default 0.

I try to do an insert with the tickbox checked (so value set to 1). Yet it doesnt insert 1 into the DB.

Equally I have an update form (same form basically), sets to 1, but update does not set to 1.

I have tried to set value to number as I believe it comes in as a string from the form, but setting to number makes no difference.

what am I doing wrong?

thanks

The checkbox only has one value, which you set in its value="" attribute. If the checkbox is not checked, then it does not send a value on form submit. It only sends this value when it is checked.

What’s your checkbox code on the page?

@JamesJenkins,

Please take a look at that great “to the point” tutorial

yeah, if checked it sends 1, if not checked nothing, on the DB field I have degault set to 0, so if not checked on the front end the DB will insert 0 and on front end if checkbox is ticked it sends 1.


and the dynamic attribute is set to Checked SC_ViewClientDetails.data.ViewClientDetails.Users_Data[0].OnWhatsapp

the checkbox works in terms of showing its checked on selecting from teh DB, but it does not do an update or insert, only if i go directly into the DB and set it to 1 it shows as ticked, if i then untick it, nothing changes on the db, equally if its unticked and i tick it nothing it sent to the server end

thanks

Can you please post your checkbox code here?

<input class="form-check-input" type="checkbox" id="OnWhatsapp" name="OnWhatsapp" dmx-bind:checked="SC_ViewClientDetails.data.ViewClientDetails.Users_Data[0].OnWhatsapp">

Your checkbox has no value set. It needs a static value 1 added so that it can send this value when it’s checked.

doh, thanks, that did it, thought with it getting dynamic value it didnt need the static.

thanks

You don’t need a dynamic value there.