![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
Join Date: Aug 2007
Location: Ohio
Posts: 46
Rep Power: 0
![]() |
PHP - quiz - why is my code not working?
Hello,
I am writing a quiz for a Harry Potter role playing site i belong to. I figured that if i made a verriable called score and add 1 to it for each correct answer it would work, but for some reason it is not. Here is my code:
<HTML>
<Head>
<Title>
Interface
</Title>
</Head>
<Body>
<Div align="center">
Welcome To the Transfigurations Midterm
<BR>
Proffesor: Damion Black
<BR>
</Div>
<Div Align="center">
<Form method="post">
Name:
<input name="Name" type="text">
<br>
<li>
What is blah
<BR>
<input name="question1" value="a" type="radio">
Answer 1
<BR>
<input name="question1" value="b" type="radio">
Answer 2
</li>
<li>
what is mah
<BR>
<input name="question2" value="a" type="radio">
Answer 1
<BR>
<input name="question2" value="b" type="radio">
Answer 2
</li>
<BR>
<input type="submit" value="submit">
<br />
</form>
<?
$score=0;
if(question1 == "a")
{
$score=$score+1;
}
if(question2 == "b")
{
$score=$score+1;
}
?>
</Div>
</Body>
</HTML>- I have also tryed taking out the PHP and puting it in its own file and using the form action as that file. - I have also tryd making the button action the php file. -I have tryed making it $score=score++ , $score+1, and $score++ none of these have worked, I know this should be simple to pull off but i can not figure it out.
__________________
Good better best, never let it rest, untill your good is better and your better is the best. |
|
|
|
|
|
#2 |
|
Professional Programmer
|
how about this ? -
php Syntax (Toggle Plain Text)
read some PHP tutorials FIRST ... ask questions later. and i think : <input name="question1" value="a" type="radio"> should be <input name="question1[]" value="a" type="radio"> but i;m not sure
__________________
Don't take life too seriously, it's not permanent ! Last edited by xavier; Aug 26th, 2007 at 4:13 AM. |
|
|
|
|
|
#3 | |
|
Programmer
Join Date: Aug 2007
Location: Ohio
Posts: 46
Rep Power: 0
![]() |
Quote:
thanks for the help both of you i apreciate it greatly
__________________
Good better best, never let it rest, untill your good is better and your better is the best. |
|
|
|
|
|
|
#4 |
|
Programmer
Join Date: Feb 2006
Location: Ohio
Posts: 93
Rep Power: 3
![]() |
You should probably have the score checking in a PHP script which your quiz form submits to. And in that score checking script, you should be checking $_GET['question1'] or $_POST['question1'], depending on your form submission method.
example form page: <form action="grade.php" method="POST"> ... </form> example score script: <?php
$score = 0;
if ($_POST['question1'] == 'a')
++$score;
if ($_POST['question2'] == 'a')
++$score;
?>
YOUR SCORE IS: <? echo $score ?>
__________________
Neeley.org |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
|
Are you ever going back to the page and the score getting reset? is that what you are trying to handle? If you are then you need to create a hidden post value of their score and when you reload the page, you have to put it in.
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
|
I did a quiz like this on Latin nouns once. I'll go downstairs and try and find the DVD with it on and then you can have a look at that if you want.
|
|
|
|
|
|
#7 |
|
Programmer
Join Date: Aug 2007
Location: Ohio
Posts: 46
Rep Power: 0
![]() |
thanks a lot matt. I got it to work though DR.p's sugestion worked. i should have posted that but thanks for offering ^_^
__________________
Good better best, never let it rest, untill your good is better and your better is the best. |
|
|
|
|
|
#8 |
|
Hobbyist Programmer
|
OK. If you need any more help just say...
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| EXECryptor software protection | Jean5 | C++ | 35 | Oct 10th, 2006 7:10 PM |
| Code library (in working progress) | Cerulean | Python | 4 | Jul 7th, 2005 8:58 AM |
| How to post a question | nnxion | C++ | 10 | Jun 3rd, 2005 11:53 AM |
| How to post a question | nnxion | C | 0 | Jun 3rd, 2005 8:55 AM |
| Code inertion not working nicely | kurifu | Community Announcements and Feedback | 5 | Jan 17th, 2005 10:08 AM |