Forum Moderators: coopster
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body>
<table border='1'>
<tr>
<th>Participant Name</th>
<th>Class</th>
<th>Day 1</th>
<th>Day 2</th>
<th>Day 3</th>
</tr>
<?php
$HOST = 'localhost';
$USERNAME = 'root';
$PASSWORD = '';
$DB = 'sjas';
$link = mysqli_connect($HOST,$USERNAME,$PASSWORD,$DB) or die (mysqli_connect_error());
$city = "SELECT m.idMember, m.name AS member_name, a.Member_idMember, cl.Course_idCourse, co.idCourse, co.name, cl.idClass
FROM member m, attendance a, Class cl, Course co
WHERE m.idMember = a.Member_idMember AND
a.Class_idClass = cl.idClass AND
cl.Course_idCourse = co.idCourse";
$result = mysqli_query($link,$city) or die(mysqli_error($link));
?>
<?php
while($row = mysqli_fetch_array($result))
{
echo "<td>".$row['member_name']."</td>";
echo "<td>".$row['idClass']."</td>";
echo '<form action="dologin.php" method="post">
<td> <select name="day_present01" >
<option value="0">Absent</option>
<option value="1">Present</option>
</select>
</td>
<td> <select name="day_present02">
<option value="0">Absent</option>
<option value="1">Present</option>
</select>
</td>
<td> <select name="day_present03">
<option value="0">Absent</option>
<option value="1">Present</option>
</select>
<input type="hidden" name = "member_id" value = "'.$row['idMember'].'" />
<input type="hidden" name = "class_id" value = "'.$row['idClass'].'" />
</td>';
echo "</tr>";
}
echo "</table>";
?>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
<?php
$day_present01 = $_POST['day_present01'];
$day_present02 = $_POST['day_present02'];
$day_present03 = $_POST['day_present03'];
$member_id = $_POST['member_id'];
$class_id = $_POST['class_id'];
$absent=0;
$present=1;
?>
<?php
if ($absent == 0)
{$absent="Absent";
}
else{
$present=="Present";}
?>
<?php
$HOST = 'localhost';
$USERNAME = 'root';
$PASSWORD = '';
$DB = 'sjas';
$link = mysqli_connect($HOST,$USERNAME,$PASSWORD,$DB) or die (mysqli_connect_error());
$course ="UPDATE attendance SET day_present01 ='$day_present01',day_present02 ='$day_present02',day_present03 ='$day_present03' WHERE Member_idMember = '$member_id'AND Class_idClass ='$class_id'";
$result = mysqli_query($link,$course) or die(mysqli_error($link));
if($result){
$statusMessage = '<p>Attendance submitted successfully.<br /><a href="view.php">View Attendance</a></p>';
}else{
$statusMessage = '<p class="error">Attendance could not be submitted. Please try again.<a href="login.php">Back</a>';
}
echo $statusMessage;
?>
foreach ($_POST as $key=>$value) {
if (preg_match('/present01\_id\_\d$/',$key)) {
list ($d,$pres,$idtag,$record_id) = explode('_',$key);
$day_one = $key;
$day_two = 'day_present02_id_' . $id;
$day_three = 'day_present03_id_' . $id;
$course ="UPDATE attendance SET day_present01 ='$value'," .
"day_present02 ='$_POST[$day_two]',day_present03 ='$_POST[$day_three]'" .
"where id='$record_id'";
// do your update
} // end if
} // End for loop
// NOW output success