开发者

HTML checkbox change value in MySQL

I have a checkbox and I need that when it is "checked" to alter a MySQL Table value to "yes" and if it's checked when you 开发者_如何学Gouncheck to "no".

I want to accomplish this with Ajax. How can this be done?


Use jQuery and PHP.

This is an example in jQuery:

 $.post("test.php", { isChecked:$('#checkbox_id').attr('checked') } );

This statement should be defined at either in the <head></head>, or in a separate JavaScript file.

And in your PHP code you can check for the isChecked POST variable:

if($_POST('isChecked')==1)
{
  //Set MySQL table to 1.
}
else
{
  //Set MySQL table to 0.
}

Here is a reference on how to use post. And here's how you can use PHP to update MySQL table.


You use the checkbox's onchange event handler to issue an XmlHttpRequest to some server-side code to update your table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜