Actually I want to submit the value of both checked and unchecked check boxes at same time using php. Will any one can help me?
This is the code which I am using now just for example so you can become more close to my problem.
In php code in first for loop I am submitting the checked values and then after that I fetch all the values from the database which are not in checked array and then I insert these values again into database in second insert query
Is there be any solution with which instead of using two insert queries I can do same thing with single query.
<!DOCTYPE html>
<html>
<body>
<?php
if (isset($_POST['submit'])) {
for ($i=0; $i < count($_REQUEST['marked']) ; $i++) {
$rollno=$_REQUEST['marked'][$i];
$check=1;
$result=$dbh->prepare("INSERT INTO attendencerecord (subjectcode, coursename, rollno,markedon, present,session,semester) VALUES('$subjectcode','$coursename','$rollno','$date','$check','$session','$semester')");
if($result->execute()){
echo 'success';
}
else{
echo 'fail';
}
}
$absents=array();
$absents=$_REQUEST['marked'];
$query="SELECT rollno FROM studentslist WHERE session = '$session' AND rollno NOT IN(".implode(',',array_map('intval',$absents)).")";
$result=mysqli_query($connection,$query);
while($ro=mysqli_fetch_array($result)){
$ro['rollno'];
$check=0;
$result1=$dbh->prepare("INSERT INTO attendencerecord (subjectcode, coursename, rollno,markedon, present,session,semester) VALUES('$subjectcode','$coursename','$ro[rollno]','$date','$check','$session','$semester')");
if($result->execute()){
echo 'success';
}
else{
echo 'fail';
}
}
}
?>
<form method="post">
<input type="checkbox" name="marked[]" id="c1" value="2901" checked />
<label for="c1">2901</label>
<input type="checkbox" name="marked[]" id="c2" value="2902" checked />
<label for="c2">2902</label>
<input type="checkbox" name="marked[]" id="c3" value="2903" checked />
<label for="c3">2903</label>
<input type="checkbox" name="marked[]" id="c4" value="2904" checked />
<label for="c4">2904</label>
<input type="checkbox" name="marked[]" id="c5" value="2905" checked />
<label for="c5">2905</label>
<button type="submit" name="submit">submit</button>
</form>