I wanted to make a quiz for my website, and I came up with a way about doing it and I need you guy's help with the code.
[Idea]
Each question will have four multiple choice answers.
You choose your answer, A B C or D [A=1 B=2 C=3 D=4], and at the end of the page when you hit done, after taking the test, and your answers are added up and the total of your answer is printed
I hope the way I presented my information was in a professional manner in which someone can help me. Thanks in advance and any input would be appreciated.
Quiz in PHP
Moderator: General Moderators
Probably about 25, but for the sake of learning it can be as many as you are willing to help me with. I want to you check boxes for the multi choice options...then depending on the one they choose they will get a number of points, then they will be added up when they click Done at the bottom of the page, then the next page will display the total points
Here goes a code I developed thus far:
Code: Select all
<?
if($submit) {
$score = $1+$2+$3;
if($score == 12) {
$message = "You're a computer WHIZ!";
} elseif($score >= 6) {
$message = "Almost! Try harder!";
} else {
$message = "Study the web and try again later."; }
echo $message; } else {
?>
<form action="<?=$PHP_SELF?>" method="post">
What is HTML used for?<br />
<input type="radio" name="1" value="1" />Getting high
<input type="radio" name="1" value="2" />Losing weight
<input type="radio" name="1" value="3" />Growing hair
<input type="radio" name="1" value="4" />Making websites
<br /><br />
What is the current PHP version?<br />
<input type="radio" name="2" value="1" />4.1.0
<input type="radio" name="2" value="2" />4.0.0
<input type="radio" name="2" value="3" />1.0.0
<input type="radio" name="2" value="4" />4.2.1
<br /><br />
What does CSS stand for?<br />
<input type="radio" name="3" value="1" />Caps Slinging Slaves
<input type="radio" name="3" value="2" />Crackattics Sniffing Stuff
<input type="radio" name="3" value="3" />Cows Seeing Supper
<input type="radio" name="3" value="4" />Cascading Style Sheets
<br /><br />
<button type="submit" name="submit" value=" Get Score! " />
</form>
<? } ?>- untouchable
- Forum Newbie
- Posts: 7
- Joined: Sat Jul 06, 2002 11:41 pm
<?
$answerArray('A', 'B', 'C', 'D', 'D', 'B', 'C');
?>
....
<input type="radio" name="$question[0]" value='A'>
<input type="radio" name="$question[0]" value='B'>
<input type="radio" name="$question[0]" value='C'>
<input type="radio" name="$question[0]" value='D'>
...
for($c = 0; $c < $sizeOfYourAnswerArray; c++)
{
if($question[$c] == $answerArray[$c])
.........
}
$answerArray('A', 'B', 'C', 'D', 'D', 'B', 'C');
?>
....
<input type="radio" name="$question[0]" value='A'>
<input type="radio" name="$question[0]" value='B'>
<input type="radio" name="$question[0]" value='C'>
<input type="radio" name="$question[0]" value='D'>
...
for($c = 0; $c < $sizeOfYourAnswerArray; c++)
{
if($question[$c] == $answerArray[$c])
.........
}