paymentstv Posted December 11, 2010 Share Posted December 11, 2010 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. Quote Link to comment Share on other sites More sharing options...
phpian Posted December 11, 2010 Share Posted December 11, 2010 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. Quote Link to comment Share on other sites More sharing options...
paymentstv Posted December 11, 2010 Author Share Posted December 11, 2010 Thank you so much. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.