Specifications
LISTING 30.2 Continued
Sorry:
<img src = ‘rosette.gif’ alt = ‘’></h1>”;
echo “<p>You need to fill in your name and answer all questions”;
}
else
{
//add up the scores
$score = 0;
if($q1 == 1) // the correct answer for q1 is 1
$score++;
if($q2 == 1) // the correct answer for q2 is 1
$score++;
if($q3 == 1) // the correct answer for q3 is 1
$score++;
//convert score to a percentage
$score = $score / 3 * 100;
if($score < 50)
{
// this person failed
echo “<h1><p align = center><img src = ‘rosette.gif’ alt = ‘’>
Sorry:
<img src = ‘rosette.gif’ alt = ‘’></h1>”;
echo “<p>You need to score at least 50% to pass the exam”;
}
else
{
// create a string containing the score to one decimal place
$score = number_format($score, 1);
echo “<h1><p align = center><img src = ‘rosette.gif’ alt = ‘’>
Congratulations
<img src = ‘rosette.gif’ alt = ‘’></h1>”;
echo “<p>Well done $name, with a score of $score%,
you have passed the exam. “;
// provide links to scripts that generate the certificates
echo “<p>Please click here to download your certificate as
a Microsoft Word (RTF) file. “;
echo “<form action = ‘rtf.php’ method = get>”;
echo “<center>
Building Practical PHP and MySQL Projects
P
ART V
756
36 7842 CH30 3/6/01 3:40 PM Page 756