Beefy Boxes and Bandwidth Generously Provided by pair Networks BBQ
Problems? Is your data what you think it is?
 
PerlMonks  

Simple Quiz Maker (yet again)

by Anonymous Monk
on Dec 06, 2003 at 04:02 UTC ( #312723=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am in dire need of advice. I posted earlier but could not get a response to my question. It is entitled "Simple Quiz Maker (cont.)". Any help wpuld be greatly appreciated. Thank you

janitored by ybiC: Retitle from less-than-descriptive "Please Help"

Comment on Simple Quiz Maker (yet again)
Re: Simple Quiz Maker (yet again)
by shockme (Chaplain) on Dec 06, 2003 at 04:44 UTC
    Referencing this node, this node, and this node, it looks as though you received some very good feedback, but have provided very little regarding any further attempts.

    What does your code look like now, and what specific problems are you experiencing? What have you learned thus far? Given the quality replies you have been given, combined with the minimal feedback on your part, I'm afraid you're going to find that this 4th thread receives very little attention.

    Perhaps you should spend a little time focusing on the resources given in the prior responses. Once you've digested that, the "direness" of your request should diminish considerably.

    Update: Made links more site-friendly and added a little whomp-ass.

    If things get any worse, I'll have to ask you to stop helping me.
Re: Simple Quiz Maker (yet again)
by Anonymous Monk on Dec 06, 2003 at 04:58 UTC
    This is my current code now. Not much different from the last one. I just need help with lines 58 - 64. I need to know how to create a 3rd page that tells the user what answers he has inputed. This is after the user presses the Submit button. Thank you.
    #!/usr/bin/perl use strict; use CGI qw(:standard); print header, start_html("Quiz Maker"), h1("Quiz Maker"); if (param()) { my $who = param("firstname"); my $who2 = param("lastname"); my $email = param("email"); my $firstquestion = param("FirstQuestion"); my $secondquestion = param("SecondQuestion"); my $thirdquestion = param("ThirdQuestion"); my $fourthquestion = param("FourthQuestion"); my $fifthquestion = param("FifthQuestion"); my $answerfirstquestion = param("AnswerFirstQuestion"); my $answersecondquestion = param("AnswerSecondQuestion"); my $answerthirdquestion = param("AnswerThirdQuestion"); my $answerfourthquestion = param("AnswerFourthQuestion"); my $answerfifthquestion = param("AnswerFifthQuestion"); my $useranswerfirstquestion = param("UserAnswerFirstQuestion"); my $useranswersecondquestion = param("UserAnswerSecondQuestion"); my $useranswerthirdquestion = param("UserAnswerThirdQuestion"); my $useranswerfourthquestion = param("UserAnswerFourthQuestion"); my $useranswerfifthquestion = param("UserAnswerFifthQuestion"); my $choicesfirstquestion = param("ChoicesFirstQuestion"); my $choicessecondquestion = param("ChoicesSecondQuestion"); my $choicesthirdquestion = param("ChoicesThirdQuestion"); my $choicesfourthquestion = param("ChoicesFourthQuestion"); my $choicesfifthquestion = param("ChoicesFifthQuestion"); print p("Thank You. Here is your quiz:"); print p("Name: $who $who2"); print hr(), start_form(); print p("Question #1: $firstquestion"); print p("Answer:", textfield("UserAnswerFirstQuestion")); print hr(), start_form(); print p("Question #2: $secondquestion"); print p("Answer:", textfield("UserAnswerSecondQuestion")); print hr(), start_form(); print p("Question #3: $thirdquestion"); print p("Answer:", textfield("UserAnswerThirdQuestion")); print hr(), start_form(); print p("Question #4: $fourthquestion"); print p("Answer:", textfield("UserAnswerFourthQuestion")); print hr(), start_form(); print p("Question #5: $fifthquestion"); print p("Answer:", textfield("UserAnswerFifthQuestion")); print hr(), start_form(); print p(submit("Submit"), reset("Reset")); print p ("Thank you for taking the quiz."); print p ("For question #1, your answer was $useranswerfirstquestio +n"); print p ("For question #2, your answer was $useranswersecondquesti +on"); print p ("For question #3, your answer was $useranswerthirdquestio +n"); print p ("For question #4, your answer was $useranswerfourthquesti +on"); print p ("For question #5, your answer was $useranswerfifthquestio +n"); print end_form(), hr(); } else { print hr(), start_form(); print p("What's your first name?", textfield("firstname")); print p("What's your last name?", textfield("lastname")); print p("Enter your e- mail address", textfield("email")); print hr(), start_form(); print p("What is your first question", textfield("FirstQuestion")) +; print p("Please enter the answer", textfield("AnswerFirstQuestion" +)); print hr(), start_form(); print p("What is your second question", textfield("SecondQuestion" +)); print p("Please enter the answer", textfield("AnswerSecondQuestion +")); print hr(), start_form(); print p("What is your third question", textfield("ThirdQuestion")) +; print p("Please enter the answer", textfield("AnswerThirdQuestion" +)); print hr(), start_form(); print p("What is your fourth question", textfield("FourthQuestion" +)); print p("Please enter the answer", textfield("AnswerFourthQuestion +")); print hr(), start_form(); print p("What is your fifth question", textfield("FifthQuestion")) +; print p("Please enter the answer", textfield("AnswerFifthQuestion" +)); print hr(), start_form(); print p(submit("Submit"), reset("Reset")); print end_form(), hr(); } print end_html
      Your problem was most admirably addressed by tcf22 and matthewb in this thread. A diff on the code given here and in that thread shows no real substantial difference -- certainly nothing which would indicate that you had applied the advice given.

      Where do you see this progressing from this point?

      If things get any worse, I'll have to ask you to stop helping me.

Re: Simple Quiz Maker (yet again)
by duff (Vicar) on Dec 06, 2003 at 05:07 UTC

    Let me try to give you some ideas ...

    It seems that you want your program to do at least 4 things:

    1. Create a quiz,
    2. store it some where
    3. let someone take a stored quiz, and
    4. display the results
    so make up a parameter (probably hidden) that gets passed to your CGI program that tells it what action you intend. Maybe even call that parameter "action". Then the main part of your program could look something like this:

    #!/usr/bin/perl use CGI qw(:standard); my $action = param('action'); $action ||= 'TakeQuiz'; if ($action eq 'CreateQuiz') { CreateQuiz(); } elsif ($action eq 'StoreQuiz' ) { StoreQuiz(); } elsif ($action eq 'ShowResults') { ShowResults(); } else { TakeQuiz(); } # default action exit;

    CreateQuiz() would present the user with a form that allows them to enter questions and answers (much the same as the code you currently have). A hidden action parameter on this form would have a value of "StoreQuiz" so that the StoreQuiz() routine can be called when you submit the form. StoreQuiz() would put the results in a file or a database or something for retrieval later. When you want to take the quiz, don't provide an action parameter and let it execute the default TakeQuiz() routine. This routine would read from where ever you stored the questions and answers and display the questions for the user to answer. A hidden parameter named "action" would be set to 'ShowResults' so that when they submitted the form, it would execut the ShowResults() routine. The ShowResults() routine would read from where ever you have the questions and answers stored, read the form data that was submitted, and produce a report that shows the user's answers and the correct answers.

    That's a rough design outline (primitive but workable). Now as far as implementing this stuff, just read the documentation for the CGI module. It's got nifty routines for saving form data to and retrieving it from files. And obviously it's got routines for reading the form data submitted by the user.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://312723]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-04-25 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (579 votes), past polls