i can update mysql database by one checkbox value 0/1 by ajax, but i don't know how to do this with multiple checkbox,
my code: index.php
<?php
$query=mysql_connect("localhost","root","root");
mysql_select_db("gpio",$query);
?>
<!DOCTYPE html>
<html>
<head>
<title>Checkbox Switches DevGrow.com</title>
<script type="text/javascript"src="jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
$('#switch1').click(function(){
var myonoffswitch=$('#switch1').val();
if ($("#switch1:checked").length == 0)
{
var a="1";
}
else
{
var a="0";
}
$.ajax({
type: "POST",
url: "ajax.php",
data: "value="+a ,
success: function(html){
$("#display").html(html).show();
}
});
});
});
</script>
</head>
<body>
<input type="checkbox" name="switch1" id="switch1"
<?php
$query3=mysql_query("select pinDescription from pindescription where pinID=1");
$query4=mysql_fetch_array($query3);
if($query4['pinDescription']=="0")
{
echo "checked";
}
?> >
</body>
</html>
ajax.php
<?php
$query=mysql_connect("localhost","root","root");
mysql_select_db("gpio",$query);
if(isset($_POST['value']))
{
$value=$_POST['value'];
mysql_query("update pindescription set pinDescription='$value' where pinID='1'");
}
?>
above code work only for one checkbox, what to do for 8 or 10 checkbox.
Aucun commentaire:
Enregistrer un commentaire