Hi!
I hope someone can help me out on this one. I have been trying to get it work since last night. I am making an application where I can add a quiz.
The quiz has questions. Each question has a certain number of choices and out of those choices one of them will be the right answer.

This is what I have thought of:
page1.php: Admin enters the question. Then he enters the number of choices he would like for that question.
page2.php: A table is created dynamically with 2 colomns. One with radio buttons and the other with text boxes. The number of rows will be determined by the value he entered on page1.php
He will enter the choices text in the textboxes and click on a radio button for the right answer.
He clicks on submit and goes to another page asking him if he wants to add another question to the quiz. If yes he goes to Page1.php.

Now, I am stuck.
I have a table called Choices which stores all the choices of the question with the questionID as a foreign key.

CREATE TABLE Choices(
Choice VARCHAR(50),
flag VARCHAR(3),
FOREIGN KEY (QuestionId) REFERENCES Questions(QuestionId));


The flag will be set to one if the radio button is checked else all values of flag are zero. Thus a right answer wll be distinguished by the flag value.


Now I created a dynamic page with table and 2 colmuns and rows. The text fields are in an array. How do I insert these values into the MySQL database. I read about the function serialize(), I read about implode()..but I tried them, it does not do what I would want it to do.


This is how I would like it to look:
<HTML>


<HEAD><TITLE>My First PHP Project</TITLE></HEAD>


<BODY>
<form action='' method='post'>
<?php


echo("<TABLE>");
echo( "\n<TR BGCOLOR=\"#E0FFFF\">");
echo("<TH>" . radiobutton. "</TH>");
echo("<TH>" . textchoice . "</TH>");


echo("</TR>");


for($j = 1; $j <= 5; $j++) {
<tr>
<td><input type="radio" id=i name="radiobutton[]" value="radiobutton"></td>
<td><input type="text" id=i  name="textfield[]"></td>
</tr>
<?php
}
echo("</TABLE>");
?>
<p align="center"><input type="submit" value="Submit" name="Submit">
<input type="reset" value="Reset" name="B2"></p>
</form
</BODY>
</HTML>

i can't figure out how to store html textfield array values into a MYSQL database using php. It is for a clas project. Please help me. I would like the daabse table to look like:

flag  choice   questionID(tis is passed from the previous page)
0     fruit?        1
0     veg?         1
1     icecream?  1

Edited 3 Years Ago by happygeek: fixed formatting

hai ...........
i am ravi i saw your mail you can do what you like but there is only one condition you should restrict the number of choices to a particular value(like 5, or 6 etc) if you accept this condition i will give you the code (but without dynamically generated database table "choices")

This article has been dead for over six months. Start a new discussion instead.