Click here to Skip to main content
16,023,224 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My table name is Attendance.If the value of checkbox is checked then I have to insert 'P'(Present) otherwise I have to insert -1(Absent).

Fields of my table, Regno ,Name,Attendance.

How to use the condition in check box using php

What I have tried:

Show All



PHP
checked=false;
function checkedAll (all) {var aa= document.getElementById('all'); if (checked == false)
{
checked = true
}
else
{
checked = false
}for (var i =0; i < aa.elements.length; i++){ aa.elements[i].checked = checked;}
}

  <?php

if(isset($_POST['insert']))
{

$ayear=$_POST['ayear'];
$course=$_POST['course'];
$year=$_POST['year'];
$sem=$_POST['sem'];
$section=$_POST['section'];
$day=$_POST['day'];
$hour=$_POST['hour'];
$dt=$_POST['dt'];
$subject=$_POST['subject'];
$attendance=$_POST['attendance'];
$lname=$_POST['lname'];

$sqlque=mysql_query("SELECT * FROM studentdetails WHERE courseid='$course' AND semester='$sem' AND section='$section' order by studid ") or die(mysql_error());
$sno=0; 
while(each($attendance))
{
$row=mysql_fetch_assoc($sqlque);
    $regno=$row['studid'];
	$atty=$attendance[$sno];

    $ins=mysql_query("INSERT INTO saa VALUES('$ayear','$dt','$year','$sem','$section','$course','$subject','$regno','$day','$lname','$atty','$hour')") or die(mysql_error());
    $sno++;
}
//echo $sno.' Records Inserted';

}
?>
Posted
Updated 28-Nov-17 22:19pm
v2
Comments
Jochen Arndt 28-Nov-17 8:54am    
I would expect the while loop to be executed over the query results
while ($row = mysql_fetch_assoc($sqlque))

and $attendance not to be an array.

1 solution

work with jQuery/Ajax, on click of checkbox insert/push the presenter name or id in an array, then send this data one by one to a php function/file to save data on the click of submit button.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900