Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 26th, 2007, 2:42 AM   #1
Kelvoron
Programmer
 
Kelvoron's Avatar
 
Join Date: Aug 2007
Location: Ohio
Posts: 46
Rep Power: 0 Kelvoron is on a distinguished road
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.
Kelvoron is offline   Reply With Quote
Old Aug 26th, 2007, 3:59 AM   #2
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
how about this ? -
php Syntax (Toggle Plain Text)
  1. <?
  2. $score=0;
  3.  
  4. if($_POST["question1"] == "a")
  5. {
  6. $score=$score+1;
  7. }
  8. if($_POST["question2"] == "b")
  9. {
  10. $score=$score+1;
  11. }
  12.  
  13. ?>

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.
xavier is offline   Reply With Quote
Old Aug 26th, 2007, 4:01 AM   #3
dr.p
Programmer
 
dr.p's Avatar
 
Join Date: Feb 2006
Location: Ohio
Posts: 93
Rep Power: 3 dr.p is on a distinguished road
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
dr.p is offline   Reply With Quote
Old Aug 26th, 2007, 5:00 AM   #4
Kelvoron
Programmer
 
Kelvoron's Avatar
 
Join Date: Aug 2007
Location: Ohio
Posts: 46
Rep Power: 0 Kelvoron is on a distinguished road
Quote:
Originally Posted by xavier View Post
and i think : <input name="question1" value="a" type="radio"> should be
<input name="question1[]" value="a" type="radio"> but i;m not sure
no you can not use an array in HTML (the form itself is HTML the driver is PHP)

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.
Kelvoron is offline   Reply With Quote
Old Aug 26th, 2007, 3:58 PM   #5
PhilBon
Hobbyist Programmer
 
PhilBon's Avatar
 
Join Date: Nov 2005
Posts: 172
Rep Power: 3 PhilBon is on a distinguished road
Send a message via AIM to PhilBon Send a message via MSN to PhilBon
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.
PhilBon is offline   Reply With Quote
Old Aug 27th, 2007, 5:25 AM   #6
mattireland
Hobbyist Programmer
 
mattireland's Avatar
 
Join Date: Jul 2007
Location: Wales, United Kingdom
Posts: 203
Rep Power: 2 mattireland is on a distinguished road
Send a message via MSN to mattireland Send a message via Skype™ to mattireland
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.
__________________
Matt Ireland
http://www.mattireland.org
matt@mattireland.co.uk
mattireland is offline   Reply With Quote
Old Aug 27th, 2007, 5:29 AM   #7
Kelvoron
Programmer
 
Kelvoron's Avatar
 
Join Date: Aug 2007
Location: Ohio
Posts: 46
Rep Power: 0 Kelvoron is on a distinguished road
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.
Kelvoron is offline   Reply With Quote
Old Aug 27th, 2007, 7:14 AM   #8
mattireland
Hobbyist Programmer
 
mattireland's Avatar
 
Join Date: Jul 2007
Location: Wales, United Kingdom
Posts: 203
Rep Power: 2 mattireland is on a distinguished road
Send a message via MSN to mattireland Send a message via Skype™ to mattireland
OK. If you need any more help just say...
__________________
Matt Ireland
http://www.mattireland.org
matt@mattireland.co.uk
mattireland is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:54 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC