javascript - Checkbox value insert into MySQL -
here front end looks like. have created checkbox email on , off, , store on/off information in mysql.
this php code
<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>better check boxes jquery , css </title> <link rel="stylesheet" type="text/css" href="css123/styles.css" /> <link rel="stylesheet" type="text/css" href="jquery.tzcheckbox123/jquery.tzcheckbox.css" /> <script src="jquery123.js"></script> <script src="jquery.tzcheckbox123/jquery.tzcheckbox.js"></script> <script src="js123/script.js"></script> </head> <body> <div id="page"> <form method="post" action=""> <br> <ul> <li><label for="ch_emails">email notifications: </label><input type="checkbox" id="ch_emails" name="ch_emails" data-on="on" data-off="off" value="1" checked/></li> </ul> </form> <?php if(isset($_post['submit'])){ if(isset($_post['ch_emails'])){ echo $check=$_post['ch_emails']; $sql=mysql_query("update scott123.rahul_tbl_users set group=$check dingoid=$dingo"); if($sql==1){ echo "checked"; } else{ echo "not checked"; }}} ?> </body> </html> ### , here javascript code (function($){ $.fn.tzcheckbox = function(options){ // default on / off labels: options = $.extend({ labels : ['on','off'] },options); return this.each(function(){ var originalcheckbox = $(this), labels = []; // checking data-on / data-off html5 data attributes: if(originalcheckbox.data('on')){ labels[0] = originalcheckbox.data('on'); labels[1] = originalcheckbox.data('off'); } else labels = options.labels; // creating new checkbox markup: var checkbox = $('<span>',{ classname : 'tzcheckbox '+(this.checked?'checked':''), html: '<span class="tzcbcontent">'+labels[this.checked?0:1]+ '</span><span class="tzcbpart"></span>' }); // inserting new checkbox, , hiding original: checkbox.insertafter(originalcheckbox.hide()); checkbox.click(function(){ checkbox.toggleclass('checked'); var ischecked = checkbox.hasclass('checked'); // synchronizing original checkbox: originalcheckbox.attr('checked',ischecked); checkbox.find('.tzcbcontent').html(labels[ischecked?0:1]); }); // listening changes on original , affecting new one: originalcheckbox.bind('change',function(){ checkbox.click(); }); }); }; })(jquery);
i tried write code information email on/off not storing in database. have created checkbox email on/off, , store on/off information in mysql, value not getting stored.
Comments
Post a Comment