logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 10-31-2011, 03:16 PM   #1
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default PHP quiz

I am looking to make a PHP quiz. There will be between 4 and 20 question per quiz, each question will have between two and four options. I don't want to add anything to a database.

I have looked around and found two tutorials Here and Here that try to teach you how to do it. But they are not very good. Can anyone please advise.

I am sure its a fairly simple thing to create but my VERY limited skill level is preventing me from achieving what i'm try to do.
tony09uk is offline   Reply With Quote
Old 11-02-2011, 08:05 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

yes its not hard. use forms and php with if conditions
if $_POST['question1'] ==1 echo "that is correct"
else echo "wrong'
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 11-02-2011, 11:03 AM   #3
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

Once again i'm guilty of over complicating things. Thanks for that.

I would like to take it a step further that though and achieve this sort of quiz. This is a quiz from my website, but it was put together using quizbox. So I don't get access to any of the code used and would like to be able to write my own.

Im not asking you to do it for me but if you can give me an idea of tutorials you know of or what php commands i need to be looking at I will do my best to work it out.

Many thanks
tony09uk is offline   Reply With Quote
Old 11-03-2011, 01:00 AM   #4
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

actually its done how i suggested, or could be. in the if condition (for correct answer, add a variable say $q1 for question 1 $q2 for question2, make the values 1 if correct 0 if wrong in the else condition then on your result page it can tally up the score $q1+$q2 etc.
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 11-03-2011, 10:48 AM   #5
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

Brilliant, thanks ed. I will get onto that over the next week and hopefully have something to show for it.

All you help as been invaluable, thanks again.
tony09uk is offline   Reply With Quote
Old 11-11-2011, 12:16 PM   #6
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

can you please advise what ive done wrong.

<form action="quiz.php" method="GET" />
Do you use a terminal?<br/>
<input type="radio" name="q1" value="1" /> Yes<br/>
<input type="radio" name="q1" value="0" /> No<br/>


how many domains do you manage?<br/>
<input type="radio" name="q2" value="0" /> I don't <br/>
<input type="radio" name="q2" value="1" /> 1<br/>
<input type="radio" name="q2" value="2" /> 2<br/>
<input type="radio" name="q2" value="3" /> 3<br/>
<input type="radio" name="q2" value="4" /> 4<br/>
<input type="radio" name="q2" value="5" /> 5 or more<br/>

<input type="hidden" name="done" value="1" />
<input type="submit" value="Submit...." />
</form>
<?php


$lopvar2=$_GET['q2'];
$lopvar1=$_GET['q1'];

$total = $lopvar2 + $lopvar1;
echo "Your total score is $total";

?>

Its telling me lopvar1 + lopvar2 are undefined index, what am I missing?
tony09uk is offline   Reply With Quote
Old 11-12-2011, 12:05 AM   #7
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

it does work although i would use $_post personally. i added eco to show the values

Code:
<form action="quiz.php" method="GET" />
Do you use a terminal?<br/>
<input type="radio" name="q1" value="1" /> Yes<br/>
<input type="radio" name="q1" value="0" /> No<br/>


how many domains do you manage?<br/>
<input type="radio" name="q2" value="0" /> I don't <br/>
<input type="radio" name="q2" value="1" /> 1<br/>
<input type="radio" name="q2" value="2" /> 2<br/>
<input type="radio" name="q2" value="3" /> 3<br/>
<input type="radio" name="q2" value="4" /> 4<br/>
<input type="radio" name="q2" value="5" /> 5 or more<br/>

<input type="hidden" name="done" value="1" />
<input type="submit" value="Submit...." />
</form>
<?php


$lopvar2= $_GET['q2'];
$lopvar1= $_GET['q1'];

echo "domain score". $lopvar2."<br>";
echo"terminal score". $lopvar1;


$total = $lopvar2 + $lopvar1;
echo "<br>"."Your total score is $total";

?>
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 11-15-2011, 08:06 PM   #8
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

I like your addition, thank you.I would have struggled with that later on. I find im getting an undefined index error.....does it matter or can I ignore it?
tony09uk is offline   Reply With Quote
Old 11-15-2011, 11:56 PM   #9
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

post the error
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 11-18-2011, 06:18 PM   #10
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

My new issues!

Problem 1)
Notice: Undefined index: q1 in file\quiz.php on line 18
Notice: Undefined index: q1 in file\quiz.php on line 19
Notice: Undefined index: q1 in file\quiz.php on line 20

Why am I getting undefined index? I have tried setting the variables below the quiz but then I get the message below each question.

Below is what I have done:

<?php
$q1 = $_POST['q1'];
$q2 = $_POST['q2'];
$q3 = $_POST['q3'];
?>
<form action="quiz.php" method="POST" />
Do you want to learn php?<br/>
<input type="radio" name="q1" value="1" /> Yes <?php if($q1 == 1) {echo "correct answer";} ?><br/>
<input type="radio" name="q1" value="0" /> No <?php if($q1 == 0) {echo "wrong answer";} ?><br/>

Are you rubbish at php?<br/>
<input type="radio" name="q2" value="1" /> Yes <?php if($q2 == 1) {echo "correct answer";} ?><br/>
<input type="radio" name="q2" value="0" /> No <?php if($q2 == 0) {echo "wrong answer";} ?><br/>

Will you get better?<br/>
<input type="radio" name="q3" value="1" /> Yes <?php if($q3 == 1) {echo "correct answer";} ?><br/>
<input type="radio" name="q3" value="0" /> No <?php if($q3 == 0) {echo "wrong answer";} ?><br/>


<input type="hidden" name="done" value="1" />
<input type="submit" value="Submit...." />
</form>

<?php
$total = $q1 + $q2 + $q3;
echo "<br>"."Your total score is $total";
?>

Problem 2)
I have taken your suggestion of showing the user where they went wrong and tried to take it a step further by showing them next to the question, but i'm struggling. It shows the user "wrong answer" before they start the quiz...obviously I don't want this. How can I solve this problem?....I know php starts counting at 0, so guess that is why it shows what i am asking it to echo, but how do i get around that?

Last edited by tony09uk; 11-18-2011 at 06:38 PM..
tony09uk is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:32 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com