Skip to content

Insert Checkbox values using Ajax Jquery in PHP

  • by

If you are looking for tutorial on how can we insert checkbox values to mysql table by using Ajax with JQuery in PHP without page refresh. Suppose you have working on any web application and in that application when user check the checkbox then at that time the value of that checkbox must be insert into mysql table without refreshing page by using Ajax with JQuery in PHP Programming.

For describing this things I have one mysql table I will insert checkbox value into that table. I have define checkboxes with values like how many subjects you have known, when user select more than one subject checkbox then all value of checkbox store into an array using Jquery and I will convert that array to string and by using Jquery ajax method I will insert values of all checkboxs to table by using PHP script.

If you wanted to learn with detail description, you can watch video which you can find top of this post.


 -- Table structure for table `tbl_subject`  
 CREATE TABLE IF NOT EXISTS `tbl_language` (  
  `id` int(11) NOT NULL AUTO_INCREMENT,  
  `subject_name` varchar(100) NOT NULL,  
  PRIMARY KEY (`id`)  
 -- Dumping data for table `tbl_subject`  


<!DOCTYPE html>  
    <title>Tutorial | Insert Checkbox values using Ajax Jquery in PHP</title>
    <script src=""></script>  
    <link rel="stylesheet" href="" />
    <script src=""></script>  
    <br />  
    <div class="container" style="width:500px;">
     <h3 class="text-center">Insert Checkbox values using Ajax Jquery in PHP</h3>
      <div class="checkbox">  
        <input type="checkbox" class="get_value" value="Physics" />Physics <br />  
    <input type="checkbox" class="get_value" value="Chemistry" />Chemistry <br />  
        <input type="checkbox" class="get_value" value="Mathematics" />Mathematics <br />  
        <input type="checkbox" class="get_value" value="Biology" />Biology <br />      
      <button type="button" name="submit" class="btn btn-info" id="submit" onClick="SumitMCQ();">Submit</button>  
      <br />  
      <div id="result"></div>
  function SumitMCQ() {
  	var subject = [];  
    	subject= subject.toString();  


      $connect = mysqli_connect("localhost", "root", "", "demo");  
      $query = "INSERT INTO tbl_subject(name) VALUES ('".$_POST["subject"]."')";  
      $result = mysqli_query($connect, $query);  
      echo 'Check Box Data Inserted';  

Good luck and I hope this article can be useful. See you in the next article…

If you enjoyed this tutorial and learned something from it, please consider sharing it with our friends and followers! Also like to my facebook page to get more awesome tutorial each week!

Leave a Reply

Your email address will not be published. Required fields are marked *