Jump to content

Submit check-box value to MySQL


paymentstv

Recommended Posts

Hello All,

 

I am new to PHP and I am trying to modify a already written script since I want to add a checkbox to my site.

In the front end I have

<input type="checkbox" name="privateurlcheck" id="privateurlcheck" value="0">

 

in the php I have

var privateurlcheck = document.getElementById( "privateurlcheck" ).value

 

Then in the mysql data insert php page,

$records[channel_protected] = $postData[privateurlcheck] ;

 

In MySQL "channel_protected" field is "ENUM" with Values '0','1'

 

When I run the code I see 0 in the MySQL channel_protected field even when I check the checkbox. All other values that are passed on to mysql such as name, age are posted correctly without any issues.

 

 

Can you please let me know how can I get 0 or 1 in the mysql depening on the checkbox status?

 

It is 5AM and I am trying to figure this for 2nd consecutive day! Greatly appreciate if any one can help me out.

 

Link to comment
Share on other sites

If a checkbox is ticked when the page is submitted it will have a value of "on", which is not an acceptable entry in your database. You need to change this to 1.

 

$records[channel_protected] = ($postData[privateurlcheck]) ? 1 : 0;

 

So if $postData[privateurlcheck] evaluates to true, it will set $records[channel_protected] to 1. if not, it will be set to 0.

 

"on" evaluates to true. "" evaluates to false.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.