Jump to content

PHP: Quiz

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
G'day everyone.

This is yet another script from one of my classes that my teacher teaches me nothing. Just copy from the .PDF and it's really bad code anyway.

This is a road sign quiz but it can be used for any type of quiz. This one you are given a picture and a list of possible answers. Each possible answer is a radio button with a specific name. When the action script is ran it then checks these answers and displays one of two pictures on the next page. One being correct and one being wrong.

There are two files.
Here is the first one.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

    <head xmlns="">

        <title>Road Sign Quiz</title>

        <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

    </head>

    <body xmlns="">

        <center><img alt="banner" src="banner.gif" /></center>

        <form action="answers.php" method="post">

            <table>

                <tbody>

                    <tr>

                        <td colspan="2"><strong><center>What does this sign mean?</center></strong></td>

                    </tr>

                    <tr>

                        <td><img alt="" src="stopsign.JPG" /></td>

                        <td><input type="radio" name="stop" value="ans1" />Go <br />

                        <input type="radio" name="stop" value="ans2" />Stop <br />

                        <input type="radio" name="stop" value="ans3" />Turn around <br />

                        <input type="radio" name="stop" value="ans4" />Stop soon <br />

                        <input type="radio" name="stop" value="ans5" />You should of stopped</td>

                    </tr>

                    <tr>

                        <td colspan="2"><strong><center>What does this sign mean?</center></strong></td>

                    </tr>

                    <tr>

                        <td><img alt="" src="10speedsign.JPG" /></td>

                        <td><input type="radio" name="speed" value="ans1" />+10 to current speed <br />

                        <input type="radio" name="speed" value="ans2" />In 10 minutes have a rest <br />

                        <input type="radio" name="speed" value="ans3" />10km till your destination <br />

                        <input type="radio" name="speed" value="ans4" />New speed limit is 100km <br />

                        <input type="radio" name="speed" value="ans5" />New speed limit is 10km per hour</td>

                    </tr>

                    <tr>

                        <td colspan="2"><strong><center>What happens at a certain time with this sign?</center></strong></td>

                    </tr>

                    <tr>

                        <td><img alt="" src="childrencrossingsign.JPG" /></td>

                        <td><input type="radio" name="child" value="ans1" /> Parents must hold childrens hands<br />

                        <input type="radio" name="child" value="ans2" /> Warning children<br />

                        <input type="radio" name="child" value="ans3" /> Children crossing<br />

                        <input type="radio" name="child" value="ans4" /> Midgets crossing<br />

                        <input type="radio" name="child" value="ans5" /> Warning</td>

                    </tr>

                    <tr>

                        <td colspan="2"><strong><center>What do you start to do after this sign?</center></strong></td>

                    </tr>

                    <tr>

                        <td><img alt="" src="endroadworksign.JPG" /></td>

                        <td><input type="radio" name="roadwork" value="ans1" /> Stop<br />

                        <input type="radio" name="roadwork" value="ans2" /> Go<br />

                        <input type="radio" name="roadwork" value="ans3" /> Go faster <br />

                        <input type="radio" name="roadwork" value="ans4" /> Prepare to stop<br />

                        <input type="radio" name="roadwork" value="ans5" /> Back to the original speed limit</td>

                    </tr>

                    <tr>

                        <td colspan="2"><strong><center>Who gives way?</center></strong></td>

                    </tr>

                    <tr>

                        <td><img alt="" src="givewaybussign.JPG" /></td>

                        <td><input type="radio" name="giveawaybus" value="ans1" /> The car<br />

                        <input type="radio" name="giveawaybus" value="ans2" /> The bus</td>

                    </tr>

                    <tr>

                        <td colspan="2"><strong><center>Where would you find this sign?</center></strong></td>

                    </tr>

                    <tr>

                        <td><img alt="" src="nothroughroadsign.JPG" /></td>

                        <td><input type="radio" name="nothrough" value="ans1" /> At the end of a street<br />

                        <input type="radio" name="nothrough" value="ans2" /> 3 streets away from a dead end<br />

                        <input type="radio" name="nothrough" value="ans3" /> Halfway down a street<br />

                        <input type="radio" name="nothrough" value="ans4" /> Beginning of a street<br />

                        <input type="radio" name="nothrough" value="ans5" /> In the bush</td>

                    </tr>

                    <tr>

                        <td colspan="2"><strong><center>What does this sign mean?</center></strong></td>

                    </tr>

                    <tr>

                        <td><img alt="" src="nouturnsign.JPG" /></td>

                        <td><input type="radio" name="nouturn" value="ans1" /> U turn permitted<br />

                        <input type="radio" name="nouturn" value="ans2" /> U turn not permitted<br />

                        <input type="radio" name="nouturn" value="ans3" /> No right turn<br />

                        <input type="radio" name="nouturn" value="ans4" /> Right turn <br />

                        <input type="radio" name="nouturn" value="ans5" /> No right turn after 6pm</td>

                    </tr>

                    <tr>

                        <td colspan="2"><strong><center>What's up ahead?</center></strong></td>

                    </tr>

                    <tr>

                        <td><img alt="" src="speedbumpsign.JPG" /></td>

                        <td><input type="radio" name="bump" value="ans1" /> A bump in the road<br />

                        <input type="radio" name="bump" value="ans2" /> Road works<br />

                        <input type="radio" name="bump" value="ans3" /> Speed bump<br />

                        <input type="radio" name="bump" value="ans4" /> Zebra crossing<br />

                        <input type="radio" name="bump" value="ans5" /> Mini shopping centre</td>

                    </tr>

                    <tr>

                        <td colspan="2"><strong><center>What does the yellow light mean?</center></strong></td>

                    </tr>

                    <tr>

                        <td><img alt="" src="trafficlightsign.JPG" /></td>

                        <td><input type="radio" name="traffic" value="ans1" /> Stop<br />

                        <input type="radio" name="traffic" value="ans2" /> Go<br />

                        <input type="radio" name="traffic" value="ans3" /> Get ready to go<br />

                        <input type="radio" name="traffic" value="ans4" /> Go if you can<br />

                        <input type="radio" name="traffic" value="ans5" /> Prepare to stop</td>

                    </tr>

                    <tr>

                        <td colspan="2"><strong><center>What does this sign mean?</center></strong></td>

                    </tr>

                    <tr>

                        <td><img alt="" src="uturnsign.JPG" /></td>

                        <td><input type="radio" name="uturn" value="ans1" /> Stay on the left side of the road <br />

                        <input type="radio" name="uturn" value="ans2" /> No U turn<br />

                        <input type="radio" name="uturn" value="ans3" /> No left turn<br />

                        <input type="radio" name="uturn" value="ans4" /> Stay on the right side of the road<br />

                        <input type="radio" name="uturn" value="ans5" /> None of the above</td>

                    </tr>

                    <tr>

                        <td colspan="2"><center><input type="submit" name="submit" value="Submit" /></center></td>

                    </tr>

                </tbody>

            </table>

        </form>

    </body>

</html>


Here is the second one.

<?php

$stop = $_POST['stop'];

$speed = $_POST['speed'];

$child = $_POST['child'];

$roadwork = $_POST['roadwork'];

$giveawaybus = $_POST['giveawaybus'];

$nothrough = $_POST['nothrough'];

$nouturn = $_POST['nouturn'];

$bump = $_POST['bump'];

$traffic = $_POST['traffic'];

$uturn = $_POST['uturn'];

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Road Sign Quiz</title></head>


<body>

<center><img src="banner.gif" alt="banner" /></center>

<table>

	<tbody>

	<tr>

        	<td colspan='2'><b><center>What does this sign mean?</center></b></td>

        </tr>

        <tr>

        	<td><img src="stopsign.JPG"/></td>

            <td>

                    Go <br />

                    Stop <br />

                    Turn around <br />

                    Stop soon <br />

                    You should of stopped

	</td>

	<td>

		<?php

			if ($stop == ans2)

				echo "<img src='correct.gif' alt='You are correct' />";

			else 

				echo "<img src='wrong.gif' alt='You are incorrect' />";

		?>

	</td>

        </tr>

        <tr>

        	<td colspan='2'><b><center>What does this sign mean?</center></b></td>

        </tr>

        <tr>

        	<td><img src="10speedsign.JPG"/></td>

            <td>

            	+10 to current speed <br />

            	In 10 minutes have a rest <br />

            	10km till your destination <br />

            	New speed limit is 100km <br />

            	New speed limit is 10km per hour            

	</td>

	<td>

		<?php

			if ($speed == ans5) 

				echo "<img src='correct.gif' alt='You are correct' />";

			else 

				echo "<img src='wrong.gif' alt='You are incorrect' />";

		?>

	</td>

        </tr>

        <tr>

        	<td colspan='2'><b><center>What happens at a certain time with this sign?</center></b></td>

        </tr>

        <tr>

        	<td><img src="childrencrossingsign.JPG"/></td>

            <td> 

       	    	Parents must hold childrens hands<br /> 

    		Warning children<br /> 

       	    	Children crossing<br /> 

       		Midgets crossing<br />

            	Warning            

	</td>

	<td>

		<?php

			if ($child == ans3) 

				echo "<img src='correct.gif' alt='You are correct' />";

			else 

				echo "<img src='wrong.gif' alt='You are incorrect' />";

		?>

	</td>

        </tr>

        <tr>

        	<td colspan='2'><b><center>What do you start to do after this sign?</center></b></td>

        </tr>

        <tr>

        	<td><img src="endroadworksign.JPG"/></td>

            <td>

            	Stop<br />

            	Go<br />

            	Go faster<br /> 

            	Prepare to stop<br />

            	Back to the original speed limit            

	</td>

	<td>

		<?php

			if ($roadwork == ans5) 

				echo "<img src='correct.gif' alt='You are correct' />";

			else 

				echo "<img src='wrong.gif' alt='You are incorrect' />";

		?>

	</td>

        </tr>

        <tr>

        	<td colspan='2'><b><center>Who gives way?</center></b></td>

        </tr>

        <tr>

        	<td><img src="givewaybussign.JPG"/></td>

            <td> 

            	The car<br />

            	The bus<br />

          	</td>

	<td>

		<?php

			if ($giveawaybus == ans2) 

				echo "<img src='correct.gif' alt='You are correct' />";

			else 

				echo "<img src='wrong.gif' alt='You are incorrect' />";

		?>

	</td>

        </tr>

        <tr>

        	<td colspan='2'><b><center>Where would you find this sign?</center></b></td>

        </tr>

        <tr>

        	<td><img src="nothroughroadsign.JPG"/></td>

            <td> 

            	At the end of a street<br />

            	3 streets away from a dead end<br /> 

            	Halfway down a street<br /> 

            	Beginning of a street<br />

            	In the bush          

	</td>

	<td>

		<?php

			if ($nothrough == ans4) 

				echo "<img src='correct.gif' alt='You are correct' />";

			else 

				echo "<img src='wrong.gif' alt='You are incorrect' />";

		?>

	</td>

        </tr>

        <tr>

        	<td colspan='2'><b><center>What does this sign mean?</center></b></td>

        </tr>

        <tr>

        	<td><img src="nouturnsign.JPG"/></td>

            <td>

            	U turn permitted<br /> 

            	U turn not permitted<br /> 

            	No right turn<br />

            	Right turn<br />

            	No right turn after 6pm            

	</td>

	<td>

		<?php

			if ($nouturn == ans2) 

				echo "<img src='correct.gif' alt='You are correct' />";

			else 

				echo "<img src='wrong.gif' alt='You are incorrect' />";

		?>

	</td>

        </tr>

        <tr>

        	<td colspan='2'><b><center>What's up ahead?</center></b></td>

        </tr>

        <tr>

        	<td><img src="speedbumpsign.JPG"/></td>

            <td> 

            	A bump in the road<br />

            	Road works<br /> 

            	Speed bump<br />

            	Zebra crossing<br />

            	Mini shopping centre            

	</td>

	<td>

		<?php

			if ($bump == ans3) 

				echo "<img src='correct.gif' alt='You are correct' />";

			else 

				echo "<img src='wrong.gif' alt='You are incorrect' />";

		?>

	</td>

        </tr>

        <tr>

        	<td colspan='2'><b><center>What does the yellow light mean?</center></b></td>

        </tr>

        <tr>

        	<td><img src="trafficlightsign.JPG"/></td>

            <td> 

            	Stop<br />

            	Go<br />

            	Get ready to go<br /> 

            	Go if you can<br />

           		Prepare to stop            

	</td>

	<td>

		<?php

			if ($traffic == ans5) 

				echo "<img src='correct.gif' alt='You are correct' />";

			else

				echo "<img src='wrong.gif' alt='You are incorrect' />";

		?>

	</td>

        </tr>

        <tr>

        	<td colspan='2'><b><center>What does this sign mean?</center></b></td>

        </tr>

        <tr>

        	<td><img src="uturnsign.JPG"/></td>

            <td>

            	Stay on the left side of the road<br />

            	No U turn<br /> 

            	No left turn<br /> 

            	Stay on the right side of the road<br />

           		None of the above            

	</td>

	<td>

		<?php

			if ($uturn == ans5) 

				echo "<img src='correct.gif' alt='You are correct' />";

			else 

				echo "<img src='wrong.gif' alt='You are incorrect' />";	 

		?>

	</td>

        </tr>

	</tbody>

</table>

</body>

</html>



#2
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
Also check out the live demo here

#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
I remember doing something similar to this in my web development class. I think we used JavaScript though. What grade did you make?

#4
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
This in grade 10, Australian standards.

But like I said, I am doing this on my own power. My teacher is giving us a .PDF and saying here you go. Type this VB script into Notepad and save it with .HTML, it runs right. You get an A+.

PHP is far beyond anyone at my school haha For the teachers anyway and I am not joking. They only know ASP.NET, HTML, and VB.

#5
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Wow, that is nice. I kinda disagree with the "if it runs right. You get an A+". If you get something to run correctly, doesn't mean it is optimal.

However really well done :D

#6
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
Yer I agree it is stupid. But that is what he says.

Thanks mate :)