Ooops, sorry Matt Kindig, i'm still trying to get this forum thing working. Anyway, let's try that again. Well, i've already checked the variables being passed, and everything was in it's place...I'm still stumped as to how to make this thing work though..
<?php
$id = stripslashes(trim($_GET["id"])); /* prepare query string */
$lname = stripslashes(trim($_GET["lname"]));
$fname = stripslashes(trim($_GET["fname"]));
$mname = stripslashes(trim($_GET["mname"]));
$mfrom = stripslashes(trim($_GET["mfrom"]));
$mto = stripslashes(trim($_GET["mto"]));
$yfrom = stripslashes(trim($_GET["yfrom"]));
$yto = stripslashes(trim($_GET["yto"]));
$today = date('Y-m-d');
$lmonth = date('m') - 01;
$curmonth = date('m');
$curmonth2 = date('F');
$curyear = date('Y');
/* Post the current month and year. */
echo "<H2 align=center><b> $curmonth2 $curyear </b></H2>";
/* Post the date today. */
echo "<b>Date Today: $today</b><br><br>";
echo "FROM: $mfrom, $yfrom<br>";
echo "TO: $mto, $yto<br>";
/* IF Structure to select the necessary query for the user. */
IF ($id == "YYMMDD-0000" && $lname == "" && $fname == "" && $mname == "")
{
$query = "select * from attendance order by cyear='$curyear' desc, mid='$curmonth' desc";
$result = mysql_query($query) /* run query */
or die(mysql_error());
}
ELSE
{
$query = "select * from attendance where (cyear between '$yfrom' and '$yto') and eid='$id' or lname='$lname' or fname='$fname' or mname='$mname' order by cyear='$curyear' desc, mid='$curmonth' desc";
$result = mysql_query($query) /* run query */
or die(mysql_error());
}
/*HTML and Computing Part of the Code*/
$num_results = mysql_num_rows($result); /* number of results */
echo "<p>Number of entries found: $num_results</p>\n";
/* HTML Code for the Titles of the Tables */
echo "<TABLE border=1 align=center valign=middle width=190%><tr align=center valign=middle><td align=center valign=top>";
echo "<colgroup span=16 align=center>";
echo "<thead class=titles><td><b>";
//echo "Add<td><b>";
//echo "Edit<td><b>";
echo "Check<td><b>";
echo "Employee ID<td><b>";
echo "Last Name<td><b>";
echo "First Name<td><b>";
echo "Middle Name<td><b>";
echo "Month ID<td><b>";
echo "Current Year<td><b>";
echo "1<td><b>";
echo "2<td><b>";
echo "3<td><b>";
echo "4<td><b>";
echo "5<td><b>";
echo "Total Late<td><b>";
echo "Total Absent</b></thead></colgroup>";
/* Start of the FORM for the submit button. */
echo "<FORM action=attendance2.php name=chkbx method=GET>";
for ($i=0; $i <$num_results; $i++) /* loop to display results */
{
//while($row = mysql_fetch_array($result))
//{
$row = mysql_fetch_array($result);
$chkid = $row["eid"];
//echo "<input type=checkbox name=approve[] value='$chkid'>";
$id1 = htmlspecialchars(stripslashes($row["eid"]));
$lname1 = htmlspecialchars(stripslashes($row["lname"]));
$fname1 = htmlspecialchars(stripslashes($row["fname"]));
$mname1 = htmlspecialchars(stripslashes($row["mname"]));
$mid1 = htmlspecialchars(stripslashes($row["mid"]));
$cyear1 = htmlspecialchars(stripslashes($row["cyear"]));
$one1 = htmlspecialchars(stripslashes($row["d1"]));
$two1 = htmlspecialchars(stripslashes($row["d2"]));
$three1 = htmlspecialchars(stripslashes($row["d3"]));
$four1 = htmlspecialchars(stripslashes($row["d4"]));
$five1 = htmlspecialchars(stripslashes($row["d5"]));
$tlate1 = htmlspecialchars(stripslashes($row["tlate"]));
$tabsent1 = htmlspecialchars(stripslashes($row["tabsent"]));
$_SESSION['eid'] = $chkid;
$_SESSION['mid'] = $mid1;
$_SESSION['cyear'] = $cyear1;
echo "<tbody class=data><td>";
//echo "<input type=checkbox name=chkemp2[] value='$chkid' onclick=document.newchk.newa.disabled=false><td>";
echo "<input type=checkbox name=chkemp[] value='$chkid' onclick=document.chkbx.chk.disabled=false><td>";
echo "$id1<td>";
echo "$lname1<td nowrap=nowrap>";
echo "$fname1<td nowrap=nowrap>";
echo "$mname1<td nowrap=nowrap>";
echo "$mid1<td>";
echo "$cyear1<td>";
echo "<input type=text name=one2 value='$one1' size=4 maxlength=4><td>";
echo "<input type=text name=two2 value='$two1' size=4 maxlength=4><td>";
echo "<input type=text name=three2 value='$three1' size=4 maxlength=4><td>";
echo "<input type=text name=four2 value='$four1' size=4 maxlength=4><td>";
echo "<input type=text name=five2 value='$five1' size=4 maxlength=4><td>";
echo "$tlate2<td>";
echo "$tabsent2<td></tbody>";
//}
//echo "<input type=hidden name=empid value=$id1>";
}
echo "</td></tr></TABLE><br>";
/* End of the FORM for the checkbox submit button. IF update button is
pressed, redirect the boxes checked to attendance update. */
echo "<input type=hidden name=empid value=$id1>";
echo "<input type=submit name=chk value='Submit'>";
echo "</FORM>";
/* Button to search again. */
/*echo "<FORM action=attendance3.php name=newchk method=GET>";
echo "<input type=submit name=newa value='New Attendance Form' disabled>";
echo "</FORM>";*/
echo "<FORM action=ctr_attendance.html>";
echo "<input type=submit value='Search Again'>";
echo "</FORM><br>";
/* close connection to database*/
mysql_close($db);
?>
This is where the processing goes:
<?php
/* Prepare the dates to be used. */
$today = date('Y-m-d');
$lmonth = date('m') - 1;
$curmonth = date('m');
$curmonth2 = date('F');
$lyear = date('Y') - 1;
$curyear = date('Y');
/* Post the current month and year. */
echo "<H2 align=center><b> $curmonth2 $curyear </b></H2>";
/* Post the date today. */
echo "<b>Date Today: $today</b><br>";
/* IF the employee status is resigned or terminated and the effectivity date is today or has passed, the employee will not be given a new attendance form. */
$query = "select id, lname, fname, mname, status, effectivity from employee where id='$eid'";
//echo $query ."<BR>"; /* Check if the query is working properly. */
$result = mysql_query($query) /* Run Query */
or die(mysql_error());
$row = mysql_fetch_array($result);
$sid = $row['id'];
$slname = $row['lname'];
$sfname = $row['fname'];
$smname = $row['mname'];
$status = $row['status'];
$effectivity = $row['effectivity'];
//echo "$sid, $slname, $sfname, $smname, $status, $effectivity<br><br>";
IF (($status=="resigned" || $status=="terminated") && $effectivity<=$today)
{
echo "<H4>The employee with ID: <b>$eid</b> is already resigned or has already been terminated.</H4><br>";
echo "<H4>Please select another employee.</H4><br>";
/* Button to return to the attendance menu. */
echo "<FORM action=ctr_attendance.html>";
echo "<input type=submit value='Search Again'>";
echo "</FORM>";
exit();
}
ELSE
{
/* Loop and update for each checked entry. */
foreach ($_GET['chkemp'] as $entry)
{
echo "<li>$checkedid[$i] \n";
$test = implode(",", $_GET['chkemp']);
echo "$test<br>";
/* Prepare the query string and get the necessary values. */
//$eid1 = $_GET['id2'];
$eid = $_SESSION['eid'];
$mid = $_SESSION['mid'];
$cyear = $_SESSION['cyear'];
$one = stripslashes(trim($_GET["one2"]));
$two = stripslashes(trim($_GET["two2"]));
$three = stripslashes(trim($_GET["three2"]));
$four = stripslashes(trim($_GET["four2"]));
$five = stripslashes(trim($_GET["five2"]));
$tlate = $one+$two+$three+$four+$five;
/* IF Structure to determine the number of "A" in a table. */
$char = "A";
$char = "a";
$letter = 0;
$num = 0;
IF($one==$char){
$letter++;
}
IF($two==$char){
$letter++;
}
IF($three==$char){
$letter++;
}
IF($four==$char){
$letter++;
}
IF($five==$char){
$letter++;
}
$tabsent = $letter;
$checkedid = $_GET['chkemp'];
$empid = $_GET["empid"];
/* Select the employee from the attendance table given the id from the ATTENDANCE.PHP page. */
$query = "update attendance set d1='$one', d2='$two', d3='$three', d4='$four', d5='$five', tlate='$tlate', tabsent='$tabsent' where eid='$entry' and mid='$mid' and cyear='$cyear'";
echo $query ."<BR>"; /* Check if the query is working properly. */
//$result = mysql_query($query) /* Run Query */
// or die(mysql_error());
}
/* IF Structure to check whether mid and cyear is equal to current month and current year. If the month and year matches the current month and year, a message will appear indicating the employee with the current attendance form. Else, a new attendance form with the current month and date will be added to the employee. */
/*IF ($mid==$curmonth && $cyear==$curyear)
{
//echo "Employee with ID: <b>$eid</b> already has an attendance form for $curmonth2 $curyear.";
}
ELSE
{
$query = "insert into attendance (eid, mid, cyear) values ('$eid', '$curmonth', '$curyear')";
//echo $query ."<BR>";
$result = mysql_query($query)
or die(mysql_error());
}
echo mysql_affected_rows() . " entry(ies) inserted into database.";*/
/* Button to search again. */
echo "<FORM action=ctr_attendance.html>";
echo "<input type=submit value='Search Again'>";
echo "</FORM><br>";
}
/* close connection to database*/
mysql_close($db);
?>