Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Info from a database to a formula

Status
Not open for further replies.

grindange

Programmer
Jul 19, 2004
18
SE
I work with Perl, CGI, MySQL and HTML....
A user have answer some question in a quiz at my site. The user want to change his answer. How can I get the users answer from the database back to the formula (pickboxes and radiobuttons), so he can change question 8 from "A" to a "B" and then save it back to a database?

/ Marcus

 
It's going to depend a bit on how you've implemented your quiz and how your database is laid out. Give us more specifics on what you've got so far. Do you have one record per question, or one record per user? Do you save the record(s) to the database as each answer is given or do you store it in cgi params or session variables and write the record(s) after the quiz is finished?

 
I have one record per user. All question is on one page, when a user press SEND all his answers go to the database.

A record in the database looks like this:
Name: Marcus
Mail: marcus@XXXX.com
Password: XXXX
q1: c
q2: b
q3: a
q4: b
q5: c
eliminationquestion: 17

How can I get his answers and data to a formula??

/ Marcus
 
If the user wants to change their answers, first retrieve them from the database. Then when you output the form, use their answers to check the correct boxes. The exact way you're going to do this depends on how you're generating the form. I'll assume you're using the CGI module's radio_group method.
Here's the example from the CGI modules documentation, modified slightly
Code:
print $query->radio_group(-name=>'group_name',
           -values=>['a','b','c','d'],
           -default=>$q1,
           -linebreak=>'true',
           -labels=>\%labels,
           -attributes=>\%attributes);
where $q1 is the person's answer to question 1 (a, b, c, or d).

If you're using straight html to output the form, you'll just need to put the 'checked' attribute in the appropriate radio button.

When the user submits again, you can simply update the database record or even delete and recreate the record.

Is this remotely close to what you needed?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top