whats wrong here why hours back to zero every time?

$time_def=$current_time-$time;
if($time_def>=15){
$totalmin=$minute+(int)($time_def/15);
if($totalmin>60){
$totalhour=$hour+(int)($totalmin/60);
$totalmin=0;
}

if($totalhour>24){
$totalday=$day+(int)($totalhour/24);
$totalhour=0;
}

$up=mysql_query("update time set
day='$totalday'
,hour='$totalhour'
,minute='$totalmin'
,sec='$sec'
,time='".time()."'
where id = '1'");
}