Need to figure out total hours between check-in and check-out times
<p>I am trying to create a check-in/check-out table in my database. My check-in form works without issue, inserting the time into my database. The problem occurs when I try to check out. Everything is good on the first entry...</p>

<p><a href="https://i.stack.imgur.com/iDNWp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iDNWp.png" alt="enter image description here"></a></p>

<p>But when I try to check in and check out again, this happens...</p>

<p><a href="https://i.stack.imgur.com/MsqH5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MsqH5.png" alt="enter image description here"></a></p>

<p>So far so good, but when I check out...</p>

<p><a href="https://i.stack.imgur.com/7TmGe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7TmGe.png" alt="enter image description here"></a>
Currently, my code updates the <code>out</code> column and <code>totalTime</code> column of all matching <code>child_id</code>'s.</p>

<p>Here is my code:</p>

<pre><code>// Select the correct child from the database
$sql_childID = "SELECT id FROM child
                WHERE firstName = '$childFirstName'
                AND lastName = '$childLastName'";
$result = $pdo-&gt;query($sql_childID);
$row = $result-&gt;fetch();
$var = $row['id'];

// Insert the check out time for the child
$query = "UPDATE checkinout
        SET `out` = :nowTime
        WHERE child_id = $var
        AND `in` IS NOT NULL";
$statement = $pdo-&gt;prepare($query);
$statement-&gt;bindValue(':nowTime', date("YmjHis"));
$statement-&gt;execute();

// Select check in time for specified child
$sql_inTime = "SELECT `in` FROM checkinout
        WHERE child_id = $var";
$inResult = $pdo-&gt;query($sql_inTime);
$inRow = $inResult-&gt;fetch();
$inTime = strtotime($inRow['in']);

// Select the check out time for specified child
$sql_outTime = "SELECT `out` FROM checkinout
        WHERE child_id = $var";
$outResult = $pdo-&gt;query($sql_outTime);
$outRow = $outResult-&gt;fetch();
$outTime = strtotime($outRow['out']);

// Find total hours
$totalTime = abs($outTime - $inTime)/(60*60);

// Update totalHours column for specified child
$queryTotalTime = "UPDATE checkinout
                SET totalTime = :totalTime
                WHERE child_id = $var
                AND 'out' IS NOT NULL";
$statement = $pdo-&gt;prepare($queryTotalTime);
$statement-&gt;bindValue(':totalTime', $totalTime);
$statement-&gt;execute();
</code></pre>