I have many checkbox items where each employee has access to different department . I want to add checked items into database.
code to display access to doors if checked
$door1 = $_POST['door1'];
echo ' dooraccess is available for ' .$door1. '<br>';
$door2 = $_POST['door2'];
echo 'dooraccess is available for ' .$door2. '<br>';
$door3 = $_POST['door3'];
echo 'dooraccess is available for ' .$door3. '<br>';
$door4 = $_POST['door4'];
echo 'dooraccess is available for ' .$door4. '<br>';
$door5 = $_POST['door5'];
echo 'dooraccess is available for ' .$door5. '<br>';
$door6 = $_POST['door6'];
echo 'dooraccess is available for ' .$door6. '<br>';
$door7 = $_POST['door7'];
echo 'dooraccess is available for ' .$door7. '<br>';
$door8 = $_POST['door8'];
echo 'dooraccess is available for ' .$door8. '<br>';
$door9 = $_POST['door9'];
echo 'dooraccess is available for ' .$door9. '<br>';
$door10 = $_POST['door10'];
echo 'dooraccess is available for ' .$door10. '<br>';
$door11 = $_POST['door11'];
echo 'dooraccess is available for ' .$door11. '<br>';
$door12 = $_POST['door12'];
echo 'dooraccess is available for ' .$door12. '<br>';
In case the values that was not checked then it will display the error as below:
Undefined index: door7 in [since door7 was not checked]
Code to insert these values along with other values to database php mysql database
if(isset($_POST['submit']))
{
$query = "INSERT INTO form_details1(firstname,secondname,location,designation,fileno,doa,doj,cardtype1,cardcolor,cardtype2,door1,door2,door3,door4,door5,door6,door7,door8,door9,door10,door11,door12,door13) VALUES('$firstname','$secondname','$location','$designation','$fileno','$doa','$doj','$cardtype1',$cardcolor,'$cardtype2','$door1','$door2','$door3','$door4','$door5','$door6','$door7','$door8','$door9','$door10','$door11','$door12')"; //query
if(mysqli_query($connect,$query)){ //check query executed or not
echo 'inserted' . '<br>' ;
}
Query doesn't insert into database since query has the values which is unchecked
I want to check all the checked items using if
loop or any other means and enter only those items that has been checked. How can I do this ?