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. Link to comment https://forums.phpfreaks.com/topic/221308-submit-check-box-value-to-mysql/ 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. Link to comment https://forums.phpfreaks.com/topic/221308-submit-check-box-value-to-mysql/#findComment-1145706 Share on other sites More sharing options...
paymentstv Posted December 11, 2010 Author Share Posted December 11, 2010 Thank you so much. Link to comment https://forums.phpfreaks.com/topic/221308-submit-check-box-value-to-mysql/#findComment-1145710 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.