Explode split separate two values in php mysql checkbox select option multiple values insert

PHP 0 Comments

Explode split separate two values in php mysql checkbox select option multiple values insert checkbox select option multiple values insert how to store option value in database in php

How to store option value in database in php

 

<?php
/*$servername='localhost';
$username='root';
$password='';
$dbname = "student";
$conn=mysql_connect($servername,$username,$password,"$dbname");
if(!$conn){
die('Could not Connect My Sql:' .mysql_error());
}*/
if(isset($_POST['save']))
{
   $checkbox = $_POST['check'];         
        for($i=0;$i<count($checkbox);$i++){
        $check_id = $checkbox[$i];		
		 $catlist = explode("-", $check_id);
        $cat = $catlist[0];
        $catname = $catlist[1];
		echo "insert into checkbox (category_id,subcategory_id,subcategory_id,status) values ('1','".$cat."','".$catname."','2')";		
		//echo "insert into checkbox (category_id,subcategory_id) values ('1','".$check_id."')";
		echo "<br>";
       // mysql_query($conn,"insert into checkbox (category_id,subcategory_id) values ('1','".$check_id."')") or die(mysqli_error());
           // echo "Data added success fully!";
       }
}
?>
    <!DOCTYPE html>
    <html>
    <head>
    </head>
    <body>
        <form method="post" action="">
        <input type="checkbox" id="checkItem" name="check[]" value="1-tech">
        <input type="checkbox" id="checkItem" name="check[]" value="<?php echo '2'; ?>-<?php echo 'edu'; ?>">
        <input type="checkbox" id="checkItem" name="check[]" value="3-job">
        <input type="checkbox" id="checkItem" name="check[]" value="4-poli">
        <button type="submit" class="btn btn-primary" style="width:200px" name="save">Submit</button>
        </form>
    </body>
    </html>

 

click and download file

on click checkbox select all and one by obe select