Home > DeveloperSection > Forums > array_diff to insert all unchecked checkbox
Tan WY
Tan WY

Total Post:3

Points:21
Posted on    August-06-2014 10:12 PM

 PHP PHP 
Ratings:


 0 Reply(s)
 1025  View(s)
Rate this:
anyone know is it possible to make INSERT all checkbox values into database when there is not even one checkbox being checked since im using array_diff as shown below?
 
my problem currently facing is,
when there is a checkbox being checked, it will insert into checked_table and the remainder options which did not selected will insert into unchecked_table.
howewer, when all checkbox didnt being selected, and click on submit button, the value didnt send to my database unchecked_table.
<?php
	include('connect.php');
	$checked =  ($_POST['date']);
	$unchecked = ($_POST['nondate']);
	$diff = array_diff($unchecked,$checked);
	
            if(isset($_POST['date']))
            {
                foreach ($_POST['date'] as $dateValue)
                {
                $insert="INSERT INTO checked_table ($colm_ladate) VALUES ('$dateValue')";
		mysql_query($insert);
                }
		echo header("location:home.php");
		}
		if (isset($_POST['nondate']))
		{
		foreach ($diff as $dateValue2)
		{
	$insert2="INSERT INTO unchecked_table($colm_lrdate) VALUES ('$dateValue2')";
	mysql_query($insert2);
		}
	echo header("location:home.php");
            }
 
?>


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

Follow MindStick