---
title: "insert different type multiple values selected in checkbox in database"  
description: "insert different type multiple values selected in checkbox in database"  
author: "Geethu gopal"  
published: 2015-08-21  
updated: 2015-08-27  
canonical: https://www.mindstick.com/forum/33423/insert-different-type-multiple-values-selected-in-checkbox-in-database  
category: "php"  
tags: ["mysql"]  
reading_time: 1 minute  

---

# insert different type multiple values selected in checkbox in database

How to [insert](https://www.mindstick.com/blog/173/executing-insert-delete-or-update-query-in-sqlserver-using-ado-dot-net) different type [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) [values selected in checkbox](https://www.mindstick.com/forum/399/how-to-insert-multiple-values-selected-in-checkbox-in-database) in [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) ,

```
<?php$checkbox1 = $_POST['batch']; $checkbox2 = $_POST['particular_name']; if(@isset($_REQUEST["sub"])){     for ($i=0; $i<sizeof($checkbox1);$i++) {     for ($j=0; $j<sizeof($checkbox2);$j++) {    $query = "INSERT INTO table(`batch`,`particular_name`) values('".$checkboxi[$i]."','".$checkbox2[$j]."')";    mysql_query($query) or die(mysql_error());    }    ?>
```

its not workin pls help me\

## Replies

### Reply by Sunil Singh

try this code

```
<?php
$checkbox1=$_POST['batch'];
$checkbox2=$_POST['particular_name'];
if(@isset($_REQUEST["sub"]))
{
if(is_array($checkbox1)&&is_array($checkbox2)){
 foreach($checkbox1 as $val)
 {

  foreach($checkbox2  as $Value)
  {
     $query = "INSERT INTO table(`batch`,`particular_name`) VALUES('".$val."','".$Value."')";
      mysql_query($query) or die(mysql_error());
  }
 }

}
}
?>
```


---

Original Source: https://www.mindstick.com/forum/33423/insert-different-type-multiple-values-selected-in-checkbox-in-database

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
