I am creating a time clock application. I have set it up so each user has their own table and it would select that table and all the rows in that table. I want to figure out how to get the difference between the in and next out punch. I am assuming that each in punch will correspond with the next out punch (the next row in the table (when ordering by ID)) I can only think of datediff. I know that is the case, but I have no clue how to implement. I am a very new php developer (Just this past week!) I have no clue how to calculate the difference between each in and out. I have looked at this question: calculate the difference of the time between In and out but couldn't figure it out there or here: mysql timeclock. Any help is appreciated.
My exact question is how to get the difference between each in and out punch in a table.
FILE:
<head>
<title>View My Punches</title>
<body bgcolor="#9966FF">
<link rel="icon" type="image/ico" href="http://example.com/time/favicon.ico"/>
</head>
<?php
error_reporting(E_ALL); ini_set('display_errors', 0);
define('DB_NAME', 'name');
define('DB_USER', 'user');
define('DB_PASSWORD', 'pass');
define('DB_HOST', 'host');
$link = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if ($link->connect_errno > 0){
die('Could not connect: ' .connect_error());
}
$userid_value = $_POST['userid'];
$table = "tc_".$userid_value;
$checkusersql = "SELECT * FROM tc_users WHERE userid = '$userid_value'";
$usercheck = $link->query($checkusersql);
$punchessql = "SELECT * FROM $table ORDER BY id";
$result = $link->query($punchessql);
$unixtime = time() + 60*60;
$time_value = date("h:i:s A", $unixtime);
$date_value = date("m/d/Y", $unixtime);
if ($usercheck->num_rows == 0) {
echo "Sorry, " . $userid_value . " is not a valid user ID. Please try again.";
}else {
echo "Punch Report for " . $userid_value . " | Generated at " . $time_value . " on " . $date_value;
echo "<p></p>";
if ($result->num_rows == 0) {
echo "<p></p>";
echo "No punches were found for " . $userid_value . ".";
}else{
echo "<table border=1>";
echo "<tr><th>Punch ID</th><th>Time</th><th>Punch Type</th><th>Group</th><th>Department</th><th>Notes</th></tr>";
while ($row = $result->fetch_array())
{
echo "<tr><td>" . $row['id'] . "</td><td>" . $row['time'] . "</td><td>" . $row['punchtype'] . "</td><td>" . $row['groupname'] . "</td><td>" . $row['dept'] . "</td><td>" . $row['notes'] . "</td>";
}
echo "</table>";
}
}
$differs = array();
$inout = array();
$current = array('in'=>array(),'out'=>array(),'length'=>'');
foreach ( $row as $each)
{
if ( $each['punchtype'] == 'in' )
{
if ( empty($current['in']) )
{ $current['in'] = $each; }
}
else if ( $each['punchtype'] == 'out' )
{
if ( empty($current['out']) )
{ $current['out'] = $each; }
}
if (( !empty($current['in']) && !empty($current['out'])))
{
$in = new DateTime($current['in']);
$out = new DateTime($current['out']);
$current['length'] = $in->diff($out);
$inout[] = $current;
$stamp = $inout['length'];
$stampformat = $stamp->format('%s');
$stampint = intval($stampformat);
$stampintval = $stampint/3600;
echo $stampintval;
#array_push($differs, );
}
}
?>
 
 
<form method="GET" action="http://example.com/time/panel.php">
<input type="submit" value="Go Home">
</form>
It will be much simpler to do this in PHP instead of in the database. Let's assume that you've pulled all the records into a variable, $allofit, and that the records are already sorted by your datetime field. Now you need to pair them up into in-out sets.
$inout = array();
$current = array('in'=>array(),'out'=>array(),'length'=>'');
foreach ( $allofit as $each)
{
if ( $each['punchtype'] == 'in' )
{
if ( empty($current['in']) )
{ $current['in'] = $each; }
}
else if ( $each['punchtype'] == 'out' )
{
if ( empty($current['out']) )
{ $current['out'] = $each; }
}
if ( !empty($current['in']) && !empty($current['out'])
{
$in = new DateTime($current['in']);
$out = new DateTime($current['out']);
$current['length'] = $in->diff($out);
$inout[] = $current;
}
}
Note that your current schema can have mis-matched in-out sets. (in # 1:14, in # 1:15, out # 1:40) This code will silently drop the mismatches; you should probably do what you can to make sure mismatches don't happen in the first place.
Related
I'm trying to get value from memcache.
value of $dataOld[$i] is null when I'm trying to read that in if statement outside of if block it contains right value.
This is my code.
My code is for get and send data .
any help will be much appreciated.
<?php
/**
* Created by PhpStorm.
* User: PC1
* Date: 9/18/2018
* Time: 11:57 AM
*/
include 'config.php';
include 'BefrestAuth.php';
include 'Publisher.php';
$memcahe = new Memcache();
$memcahe->connect("localhost", 11211);
$dataNew = json_decode($memcahe->get('keyNew'));
$memcahe->set('keyOld', json_encode($dataNew));
while (true) {
$dataNew = json_decode($memcahe->get('keyNew'));
$dataOld = json_decode($memcahe->get('keyOld'));
if (!$dataNew[0]->price) {
continue;
} else {
$str = "";
$taskolu = array();
for ($i = 0; $i < count($dataNew); $i++) {
if ((int)$dataNew[$i]->price > (int)$dataOld[$i]->price) {
echo "\n".$dataNew[$i]->price."/////".json_encode($dataOld[$i])."\n";
$str .= "name:" . $dataNew[$i]->name . " type:" . $dataNew[$i]->type . " price:" . $dataNew[$i]->price."\n";
array_push($taskolu, $dataNew[$i]);
}
if ((int)$dataOld->price > (int)$dataNew[$i]->price) {
$str .= "name:" . $dataNew[$i]->name . " type:" . $dataNew[$i]->type . " price:" . $dataNew[$i]->price."\n";
array_push($taskolu, $dataNew[$i]);
}
}
if (!empty($str)) {
$dbca = connection();
$dbca->set_charset("utf8");
$rate = "SELECT u.user_chid FROM users u";
$result = $dbca->prepare($rate);
$result->execute();
$res = $result->get_result();
while ($obj = $res->fetch_object()) {
$auth = (string)BefrestAuth::generatePublishAuth($obj->user_chid);
Publisher::publish(11812, $obj->user_chid, $auth, json_encode(array("messages" => $taskolu)));
echo "\n";
}
}
$memcahe->delete('keyOld');
$data=json_encode($dataNew);
$memcahe->set('keyOld', $data);
$dataOld = json_decode($memcahe->get('keyOld'));
}
}
I'd like to show dropdown menu(s) that contain the selected day based on what is recorded on the database.
Is there any efficient way to dynamically change the selected state of the dropdown menu based on the recorded data?
Thank you
note:
There will be many dropdown menu(s) if the recorded day of the following clinicID is more than one row
The $day is an integer, 1 for Sunday, 2 for Monday and so on
Here is mycode
// Check if any row existed
if ($count>0) {
// If row existed then start printing it
while($row = mysql_fetch_assoc($retval))
{
$day = $row['day'];
$startHour = $row['startHour'];
$startMin = $row['startMin'];
$endHour = $row['endHour'];
$endMin = $row['endMin'];
echo
"<span>" .
"<select name='day[]'>" .
"<option value='1' selected='selected'>Sunday</option>" .
"<option value='2'>Monday</option>" .
"<option value='3'>Tuesday</option>" .
"<option value='4'>Wednesday</option>" .
"<option value='5'>Thursday</option>" .
"<option value='6'>Friday</option>" .
"<option value='7'>Saturday</option>" .
"<option value='0'>Everyday</option>" .
"</select>"
//Please ignore this below
"<br>start : " . $startHour . "." . $startMin .
"<br>end : " . $endHour . "." . $endMin .
"<br><br>";
}
}
else {
}
If this is new code, please use PDO or MySQLi. mysql is depreciated and should not be used on new code php.net/manual/en/function.mysql-query.php Try this link, it helped me a lot: phpdelusions.net/pdo
Change your code to something like this (This code includes PDO implementation):
<?php
$db = new PDO('mysql:host=yourhost;dbname=dbname', 'username', 'password', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"));
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//Printing schedule already in the database
$getbusinesshours = "select * from businesshours where clinicID = $clinicID";
$stmt = $db->prepare($getbusinesshours);
$stmt->execute();
$count = $stmt->rowCount();
// Check if any row existed
if ($count>0){
// If row existed then start printing it
foreach ($stmt as $row){
{
$day = $row['day'];
$startHour = $row['startHour'];
$startMin = $row['startMin'];
$endHour = $row['endHour'];
$endMin = $row['endMin'];
$i = 0;
$days = array('Everyday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
$select = '<span><select name="day[]">';
while($i <= 7){
if($i == $day){
$selected = 'selected="selected"';
}
else{
$selected = '';
}
$select = $select.
'<option value="'.$i.'"'.$selected.'>'.$days[$i].'</option'>
$i++;
}
$select = $select.'</select>';
echo $select;
//Please ignore this below
"<br>start : " . $startHour . "." . $startMin .
"<br>end : " . $endHour . "." . $endMin .
"<br><br>";
}
}
else {
}
?>
I hope this helps.
I want to create a basic time slot booking system. But I've run into some problems.
I have created a calendar where I can see that something is happening on a speific date:
It takes the information from my database table. I'm using PHPMyAdmin, and I've added the date manually in there.
As you can see in the table, I would also like to use a start time and an endtime.
If I click a date in my calendar, I create the add-event link like this:
<?php
if (isset ( $_GET ['v'] )) {
echo "<a href='test.php . ?month=" . $month . "&day=" . $day . "&year=" . $year . "&v=true&f=true'>Add Event</a>";
if (isset ( $_GET ['f'] )) {
include ("test.php");
}
$sqlEvent = "SELECT * FROM calendar WHERE eventDate='" . $month . "/" . $day . "/" . $year . "'";
$resultEvents = mysqli_query ( $mysqli1, $sqlEvent );
echo "<br>";
while ( $events = mysqli_fetch_array ( $resultEvents ) ) {
}
}
?>
Clicking this makes my url look somehting like this: test.php%20.%20?month=04&day=18&year=2014&v=true&f=true#
I've included my whole test.php file:
<?php
$hostname = 'localhost';
$username = 'root';
$password = '';
$dbname = "calendar";
$error = 'Cannot connect to the database';
$mysqli1 = new mysqli ( $hostname, $username, $password, $dbname ) or die ( $error );
if (isset ( $_GET ['day'] )) {
$day = $_GET ['day'];
} else {
$day = date ( "j" );
}
if (isset ( $_GET ['month'] )) {
$month = $_GET ['month'];
} else {
$month = date ( "n" );
}
if (isset ( $_GET ['year'] )) {
$year = $_GET ['year'];
} else {
$year = date ( "Y" );
}
$dateToCompare = $month . '/' . $day . '/' . $year;
echo "<br/><br/><h3>Reservations</h3>";
$timearray = array(8,9,10,11,12,13,14,15,16,17,18,19,20,21,22);
$tablecolor = 1;
echo "<table style='width: 90%;'>";
echo "<tr>";
echo "<th>";
echo "Time";
echo "</th>";
echo "<th>";
echo "Status";
echo "</th>";
echo "</tr>";
foreach ($timearray as $timearrays) {
if($tablecolor %2 == 0) {
echo "<tr>";
}
else {
echo "<tr style='background-color: rgb(0,100,255); background: rgb(0,100,255);'>";
}
echo "<th>";
if ($timearrays == 8) {echo "<h3>8-9am</h3>";}
if ($timearrays == 9) {echo "<h3>9-10am</h3>";}
if ($timearrays == 10) {echo "<h3>10-11am</h3>";}
if ($timearrays == 11) {echo "<h3>11-12am</h3>";}
if ($timearrays == 12) {echo "<h3>12-13am</h3>";}
if ($timearrays == 13) {echo "<h3>13-14am</h3>";}
//Develop your timeslots here to display as required
echo "</th>";
echo "<td>";
$sql = "SELECT * FROM calendar WHERE eventDate='" . $dateToCompare . "'AND timestart >= $timearrays AND endtime <= $timearrays;";
$result = mysqli_query($mysqli1,$sql);
if (mysqli_num_rows($result) == 0) {
echo "<a href='#'><h3 style='color: rgb(255,0,0);'>Reserve</h3></a>";
} else {
echo "<h3>Not Available, taken by someone</h3>";
while($row = mysql_fetch_array($result)) {
echo "<br />";
}
}
echo "</td>";
echo "</tr>";
$tablecolor++;
}
echo "</table>";
?>
As you can see, I try to display my timeslots: $sql = "SELECT * FROM calendar WHERE eventDate='" . $dateToCompare . "'AND timestart >= $timearrays AND endtime <= $timearrays;";
I think that I get my dates correctly from the URL, but I don't see any reservations for a given date.
I hope that some of you can help me out. And please ask, if I need to provide more of my code.
Or if anyone has a better idea on how to do this, please share.
I'm not really sure if I should be conserned about time. I basically just want the ability to click on "Reserve" and then reverse that specific time slot. So maybe a start and an end time isn't nessary?
Try to debug your application. But I guess the problem will probably be the $timearrays in the query you create. I don't think (haven't tested) it works that way.
My suggestion, print out $sql after you've initialized it and see what it returns. Then open PHPmyadmin (which I guess you're using, by the looks of your data) and see what it returns there.
I'm kinda new to php, this place has been a great help for me so far! Anyway, I have this code
$month = "
SELECT SUM(`duration`)
FROM `connlist` AS `month_sum`
WHERE `vatsimid` = '$vatsimid'
AND MONTH(atc_online) = " . $pmonth . "
AND YEAR(atc_online) = " . $year . "
";
That's what I get when I echo out $month
SELECT SUM(`duration`)
FROM `connlist` AS `month_sum`
WHERE `vatsimid` = '1070757'
AND MONTH(atc_online) = 07
AND YEAR(atc_online) = 13
When i use this directly into phpMyAdmin, works as a charm, but when I try to do it through a php webpage, I get the syntax error. I'm using php 5.4
Thanks!
Edit: Full Code:
<?php
//open MySQL connection
$mysql = mysqli_connect('host', 'un', 'pass', 'table')
or die ( "MySQL Error: ".mysqli_error() );
//Get and decode residents data
$jsonData = file_get_contents("link");
$phpArray = json_decode($jsonData, true);
//Start Operations
foreach ($phpArray as $key => $value) {
//Get controller hours for today
$vatsimid = $value[vatsimid];
//Get previous month
$pmonth = date("m", strtotime("-35 days") ) ;
$pmonthName = date("M", strtotime("-35 days") ) ;
echo $pmonth;
echo $pmonthName;
//This year or last year?
If (date("M") != "Jan") { //Checks that it's not January of the next year.
$year = date("y");
}
else {
$year = date("y", strtotime("-1 month") );
}
echo $year;
//Search and sum entries during last month
$month = "SELECT SUM(`duration`)
FROM `connlist` AS `month_sum`
WHERE `vatsimid` = '$vatsimid'
AND MONTH(atc_online) = " . $pmonth . "
AND YEAR(atc_online) = " . $year . "";
echo $month;
echo "</br> </br>";
$result = mysqli_query($mysql,$month);
$row = mysqli_fetch_assoc($result);
$month_sum = $row['month_sum'];
echo $month_sum;
//Updates data in atclist
$datainsert = "
UPDATE `atclist`
SET " . $monthName . "=" . $month_sum . "
WHERE vatsimid = " . $vatsimid . "";
$insert = mysqli_query($mysql,$datainsert);
if (!$insert)
{
die('Error: ' . mysqli_error($mysql));
}
}
/*
Did you mean:
SELECT SUM(duration) AS month_sum
FROM connlist
WHERE vatsimid = '1070757' AND MONTH(atc_online) = 07 AND YEAR(atc_online) = 13
It looks like $month_sum variable is not set or empty in your UPDATE query.
You can add single quotes like
$datainsert = "
UPDATE atclist
SET ".$monthName."= '".$month_sum."'
WHERE vatsimid= '".$vatsimid."'";
I have an attendance page which outputs a list of students in a class through the following loop:
$sql10 = "SELECT class.name, student_to_class.class_id, student_to_class.student_id
FROM
student_to_class
INNER JOIN
class
ON class.id=student_to_class.class_id
WHERE
class.name = '$classid'";
$result10 = mysql_query($sql10) or die(mysql_error());
while ($row = mysql_fetch_array($result10)) {
$student = $row['student_id'];
$classid = $row['class_id'];
$sql3 = "select * from student where id = '$student'";
$result3 = mysql_query($sql3) or die(mysql_error());
$row3 = mysql_fetch_assoc($result3);
$studentfname = $row3['first_name'];
$studentlname = $row3['last_name'];
$sql4 = "select * from student where first_name = '$studentfname' AND last_name = '$studentlname'";
$result4 = mysql_query($sql4) or die(mysql_error());
$row4 = mysql_fetch_assoc($result4);
$studentrfid = $row4['rfid'];
$sql5 = "select * from class where id = '$classid'";
$result5 = mysql_query($sql5) or die(mysql_error());
$row5 = mysql_fetch_assoc($result5);
$class_name = $row5['name'];
//Define the default variables assuming attendance hasn't been taken.
$david = "select * from student where rfid='$studentrfid'";
$davidresult = mysql_query($david) or die(mysql_error());
$drow = mysql_fetch_assoc($davidresult);
if (($drow['excused'] == '1') && ($drow['excuseddate'] == $date)) {
//if($drow['excuseddate'] == $date;
$excusedabsense = '<option value="Excused Absense" label="Excused Absense" selected="selected">Excused Absense</option>';
} else {
$excusedabsense = '';
}
$presentpunctual = '<option value="Present" label="Present">Present</option>';
$presenttardy = '<option value="Tardy" label="Tardy">Tardy</option>';
$unexcusedabsense = '<option value="Absent" label="Absent">Absent</option>';
if (isset($_POST['editdate'])) {
$date = $_POST['date'];
}
$realfname = $studentfname;
$reallname = $studentlname;
$sql4 = "select * from attendance_main where StudentID = '$studentrfid' AND date = '$date' AND classID = '$class_name'";
$result4 = mysql_query($sql4) or die(mysql_error());
$row4 = mysql_fetch_assoc($result4);
if ($row4['status'] == "Present") {
$presentpunctual = '<option value="Present" label="Present" selected="selected">Present</option>';
} else {
$presentpunctual = '<option value="Present" label="Present">Present</option>';
}
if ($row4['status'] == "Tardy") {
$presenttardy = '<option value="Tardy" label="Tardy" selected="selected">Tardy</option>';
} else {
$presenttardy = '<option value="Tardy" label="Tardy">Tardy</option>';
}
if ($row4['status'] == "Absent") {
$unexcusedabsense = '<option value="Absent" label="Absent" selected="selected">Absent</option>';
} else {
$unexcusedabsense = '<option value="Absent" label="Absent">Absent</option>';
}
$b++;
echo "<tr>";
if (!isset($dateform)) {
$dateform = date('m/d/Y');
}
$date = date('m/d/Y');
echo '<td><iframe src="flag.php?&flagdate=' . $dateform . '&curdate=' . $date . '&class=' . $classid . '&flag=1&user=' . $studentrfid . '&curflag=' . $realrfid['flag'] . '&flagclass=' . $classname . '" width="50" height="30" frameborder="0" scrolling="no"> </iframe></td>';
//Yesterday
$sql8 = "select * from attendance_main where StudentID = '$studentrfid' AND date='$yesterdaysql' AND classID = '$class_name'";
$result8 = mysql_query($sql8) or die(mysql_error());
$tooltiprow = mysql_fetch_assoc($result8);
if (mysql_num_rows($result8) == 0) {
$tooltipresult_yesterday = "N/A";
} else {
$tooltipresult_yesterday = $tooltiprow['status'];
}
//2 days
$sql8 = "select * from attendance_main where StudentID = '$studentrfid' AND date='$days2sql' AND classID = '$classid'";
$result8 = mysql_query($sql8) or die(mysql_error());
$tooltiprow = mysql_fetch_assoc($result8);
if (mysql_num_rows($result8) == 0) {
$tooltipresult_2days = "N/A";
} else {
$tooltipresult_2days = $tooltiprow['status'];
}
//3 days
$sql8 = "select * from attendance_main where StudentID = '$studentrfid' AND date='$days3sql' AND classID = '$class_name'";
$result8 = mysql_query($sql8) or die(mysql_error());
$tooltiprow = mysql_fetch_assoc($result8);
if (mysql_num_rows($result8) == 0) {
$tooltipresult_3days = "N/A";
} else {
$tooltipresult_3days = $tooltiprow['status'];
}
$tooltip = "<b>" . $yesterday . ":</b> " . $tooltipresult_yesterday . " - <b>" . $days2 . ":</b> " . $tooltipresult_2days . " - <b>" . $days3 . ":</b> " . $tooltipresult_3days;
echo "
<!-- Loop #" . $b . " --> <td><a href='#'";
?> onMouseover="ddrivetip('<?php
echo $tooltip;
?>')"; onMouseout="hideddrivetip()"> <?php
echo $realfname . " " . $reallname . "</a></td>";
echo '<td>
<select name="status' . $b . '">
' . $presentpunctual . '
' . $presenttardy . '
' . $excusedabsense . '
' . $unexcusedabsense . '
</select>
' . $hiddenfield . '
<input type="hidden" name="i" value="' . $b . '" />
<input type="hidden" name="studentid' . $b . '" value="' . $studentrfid . '">
<input type="hidden" name="classid" value="' . $class_name . '"></td>
<td><input type="text" name="comments' . $b . '" size="40" /></td></tr>
<!-- End Loop -->';
}
}
}
It essentially prints out student name and a drop down of statuses (if attendance was taken that day, the status will be whatever is set in the database). The date, flag, and tooltip functions are extra additions. (Date is for previous days, tooltip shows previous attendance on hover)
This data is being executed through the following loop:
if (isset($_GET['update'])) {
mysql_query("UPDATE teacher_accounts SET attendance = '1' WHERE username = '$username'") or die(mysql_error());
$error = 0;
$limit = $_GET['i'];
$starter = 0;
$num = 0;
while ($starter < $limit) {
$num++;
$statusinc = "status" . $num;
$studentinc = "studentid" . $num;
$commentsinc = "comments" . $num;
$starter++;
$studentID = $_GET[$studentinc];
$status = $_GET[$statusinc];
$comments = $_GET[$commentsinc];
$date = date("m/d/Y");
$sql = "select * from student where id = '$studentID'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$classid = $_GET['classid'];
if (isset($_GET['dateedit'])) {
$date = $_GET['dateedit'];
$count = "select * from attendance_main where StudentID = '$studentID' AND date = '$date' AND classID='$classid'";
$cresult = mysql_query($count) or die(mysql_error());
if (mysql_num_rows($cresult) > 0) {
$sql = "UPDATE attendance_main SET status='$status',comments='$comments',date='$date',classID='$classid' where StudentID = '$studentID'";
} else {
$sql = "INSERT INTO attendance_main (StudentID,status,comments,date,classID) VALUES ('$studentID','$status','$comments','$date','$classid')";
}
if (mysql_query($sql)) {
$return = "<h3>Successfully updated the attendance.</h3>";
}
} else {
$count = "select * from attendance_main where StudentID = '$studentID' AND date = '$date' AND classID='$classid'";
$cresult = mysql_query($count) or die(mysql_error());
if (mysql_num_rows($cresult) > 0) {
$sql = "UPDATE attendance_main SET status='$status',comments='$comments',date='$date',classID='$classid' where StudentID = '$studentID'";
if (mysql_query($sql)) {
$return = "<h3>Successfully updated the attendance for " . $num . " students.</h3>";
}
} else {
$sql = "INSERT INTO attendance_main (StudentID,status,comments,date,classID) VALUES ('$studentID','$status','$comments','$date','$classid')";
if (mysql_query($sql)) {
$return = "<h3>Successfully inserted today's attendance for " . $num . " students.";
}
}
}
}
echo $return;
For some reason, data is sometimes not being inserted properly. For example, a teacher might submit attendance on 02/08/2011, for a specific class, and certain students might appear twice under that attendance. This shouldn't be the case according to the code, because it should first check if they exist and, if they do, update the record rather than insert.
I've also seen cases where records are randomly deleted altogether. When a teacher takes attendance, all statuses are automatically set to Present. However, when I searched records on a certain date in the database, 2 students were missing records (which isn't even possible unless its being deleted)
Anyone have any idea why this might happen? I've tried replicating it myself (by repeatedly submitting the form, refreshing the page after it's processed, etc, to no avail.)
Thank you for the help!
Your query that check if a record exists is looking for all 3. 1) $studentID, 2) $classid and 3) $classid However the UPDATE statement is just looking for $studentID.
I would suggest you create a PRIMARY KEY (or UNIQUE INDEX) on StudentID,date,classID, then use the MySql INSERT ON DUPLICATE KEY UPDATE...
INSERT INTO attendance_main (StudentID,status,comments,date,classID)
VALUES ('$studentID','$status','$comments','$date','$classid')
ON DUPLICATE KEY UPDATE
status = VALUES(status),
comments = VALUES(comments)
Don't forget to sanitize the database input by using mysql_real_escape_string for example $status = mysql_real_escape_string($_GET[$statusinc]);.