javascript - checkbox question with php -
my question when user click on checkbox, user activated. code working fine. when user again click on uncheckbox, again user de-activated. how that? here working code.
activate user when user click on checkbox
if($_get['doaction'] == 'activate') { if(!empty($_get['q'])) { $userid = $_get['q']; $conn = db_connection(); $query = "update user set activate = '1' userid = '".$userid."' "; $result=$conn->query($query); } }
here checkbox
<input type="checkbox" name="app" onchange="calluser(this.value,doaction.value);" value="<?php echo $userid;?>" <?php if($row['approved'] == '1'){ echo "checked=\"true\""; }?>/> <input type="hidden" name="doaction" id="doaction" value="approved" />
thanks much. :-) edit-> here calluser() function
<script type="text/javascript"> function calluser(str,action,third) { var xmlhttp; if (str=="") { document.getelementbyid("txthint").innerhtml=""; return; } if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getelementbyid("txthint").innerhtml=xmlhttp.responsetext; } } xmlhttp.open("get","adminpanel.php? q="+str+"&doaction="+action+"&app="+third,true); xmlhttp.send(); } </script>
here screenshot http://i.stack.imgur.com/mpqfc.png
you should send state of checkbox rather hidden field value.
onchange="calluser(<?php echo $userid;?>,this.value);"
then on php side can a
$userid = $_get['q']; if(!empty($_get['doaction']) { ... activate ... } else { ... deactivate ... }
also, please aware code sample , anwser both extremely insecure. wide open sql injection attacks , potential permission problems.
edit : fix not sending user id.
Comments
Post a Comment