problem with dynamically created textbox&radiobutton in

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
payalshetty
Forum Newbie
Posts: 1
Joined: Sat Mar 26, 2005 3:19 pm

problem with dynamically created textbox&radiobutton in

Post by payalshetty »

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 textbxes and click on a radio button for te 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.

Code: Select all

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:

Code: Select all

<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:

Code: Select all

flag choice  questionID(tis is passed from the previous page)
0     fruit?     1
0     veg?       1
1     icecream?  1
could someone help me please?


feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

insert each set of data into the table seperately. By the way, you'll have a tough time figuring out which radio button is the one selected, as a browser will only send the selected one. In other words, set the value to $j.
Post Reply