Home > DeveloperSection > Forums > insert different type multiple values selected in checkbox in database
Geethu gopal
Geethu gopal

Total Post:1

Points:7
Posted on    August-21-2015 11:42 PM

 PHP MYSQL 
Ratings:


 1 Reply(s)
 504  View(s)
Rate this:
How to insert different type multiple values selected in checkbox in database ,
<?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



Sunil Singh
Sunil Singh

Total Post:11

Points:77
Posted on    August-27-2015 5:18 AM

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());
  }
 }
 
}
}
?>

Modified On Aug-27-2015 05:20:05 AM

Don't want to miss updates? Please click the below button!

Follow MindStick