function dierror($dbhandle)
    {
        if (strpos(mysql_error(), "right syntax to use near '") !== false) {
            $_SESSION["phase1done"] = "true";
            echo mysql_error() . "<br /></div><br />";
            ?>
<div style="font-size: 1.3em">
  Well done! :)<br />
  Proceed to Phase 2 by clicking <a href="phase2.php">here</a>
</div>
<?php 
            mysql_close($dbhandle);
            die;
        } else {
            echo mysql_error() . "<br /></div>";
        }
        mysql_close($dbhandle);
        checkdone();
        die;
    }
        // If none fetched, warn:
        if ($count2 == 0) {
            ?>
<br />
<center><h3>No records were fetched!</h3></center>
<?php 
        }
    } else {
        ?>
<br />
<center><h3>Error fetching records for Query 2</h3></center>
<?php 
    }
    ?>
</td></tr></table>
<?php 
    // Check for Phase 5
    if ($count1 == 10 && $count2 == 10) {
        $_SESSION["phase4done"] = "true";
        ?>
<br /><div style="font-size:1.3em">
  Phew! You got done with Phase 4 as well!<br />
  Proceed to Phase 5 <a href="phase5.php">here</a>.
</div>
<?php 
        die;
    }
    checkdone();
} else {
    checkdone();
}