Simple software applications can be produced very quickly using HTML with the scripting language PHP. Below is a quiz with five general knowledge questions written using HTML and PHP.
This tutorial assumes some very basic knowledge of HTML and PHP scripting languages and their architectures.
Without going into too much detail, HTML script reads like you do, from top to bottom, left to right. The HTML is separated into certain sections using pre-defined tags. The tags enforce structure.
An example:-
<strong>Hello World!</strong> The birds are singing!
In the example, the <strong> tag is used to make the Hello World! text bold whereas the, “The birds are singing!” text is of normal weight. Generally, each tag needs to be started and ended.
The example code below uses a form and table structure to display the questions and answers. As you can see, the pre-defined tags are used to display the table, <table> and each row, <tr>, and column <td>. You will notice each tag is ended using the same tag but with a preceding slash.
The PHP code is used to determine whether the Score button was pressed, and further down calculates the total number of questions that have been answered correctly.
Let us begin…
<!-- These two tags start the HTML code and head sections -->
<html>
<head>
<!-- The title tags displays the page title in the browser -->
<title>The Liquid Quiz</title>
</head>
<!-- The body tags starts the main content of the site -->
<body>
<!-- Display a title in bold -->
<strong>THE Quiz!!!</strong>
<!-- Start the PHP code -->
<?php
// The Score button has not been pressed yet
if ($_POST[”scoreme”] == “”)
{
?>
<!– Start the form and point to the web page that will be loaded when the Score button is pressed –>
<form action='index.php' method='post'>
<!-- Start the table and remove the the border and increase the space between each cell -->
<table border='0' cellpadding='5'>
<tr>
<!– Display the first question with two possible answers –>
<td><strong>By what name is the cartoon character, Norville Rogers, better known?</strong></td>
<td><select name=’questionone’>
<!-- By giving the correct answer the value of one, the posted data can be simply added up instead of comparing the answers -->
<option value='0'>Super Ted</option>
<option value=’1′>Shaggy</option>”
</select>
</td>
</tr>
<tr>
<td><strong>Who is the elder of football’s Charlton brothers? Jack or Bobby?</strong></td>
<td><select name=’questiontwo’>
<option value=’0′>Bobby</option>
<option value=’1′>Jack</option>”
</select>
</td>
</tr>
<tr>
<td><strong>What colour is the letter B in the eBay logo?</strong></td>
<td><select name=’questionthree’>
<option value=’0′>Red</option>
<option value=’1′>Blue</option>”
</select>
</td>
</tr>
<tr>
<td><strong>The Omega watch worn by which actor as he made his debut as James Bond was recently sold at auction for £102,712?</strong></td>
<td><select name=’questionfour’>
<option value=’1′>Daniel Craig</option>
<option value=’0′>Timothy Dalton</option>”
</select>
</td>
</tr>
<tr>
<td><strong>What were the Nolan Sisters in the mood for in 1979?</strong></td>
<td><select name=’questionfive’>
<option value=’1′>Dancing</option>
<option value=’0′>Drinking</option>”
</select>
</td>
</tr>
<tr>
<!– Display the Score button. Once clicked, the page will be reloaded with the answers given. This section of code will then be skipped. –>
<td colspan='2'><input type="submit" value="Score" name="scoreme" />
</td>
</tr>
</table>
<?php
}
// Questions have been answered and the Score button has been pressed
else
{
// Set up the total, giving it an initial value of 0
$total = 0;
�
// Calculate the total score from each answer
$total = $_POST[”questionone”] + $_POST[”questiontwo”] + $_POST[”questionthree”] + $_POST[”questionfour”] + $_POST[”questionfive”];
// Display two blank lines and then display the total out of 5.
echo “<br /><br />You got “.$total.” out of 5″;
}
// End the PHP code
?>
<!– End the tags, started at the top of the code –>
</body>
</html>







