dynamically generated textboxes & radio buttons php, insert into db

Reply

Join Date: Mar 2005
Posts: 1
Reputation: seemajanardhan is an unknown quantity at this point 
Solved Threads: 0
seemajanardhan seemajanardhan is offline Offline
Newbie Poster

dynamically generated textboxes & radio buttons php, insert into db

 
0
  #1
Mar 26th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 204
Reputation: pcschrottie is an unknown quantity at this point 
Solved Threads: 8
pcschrottie's Avatar
pcschrottie pcschrottie is offline Offline
Posting Whiz in Training

Re: dynamically generated textboxes & radio buttons php, insert into db

 
0
  #2
Mar 27th, 2005
html textfield array values
Is this a creation of your own? Because I haven't seen it yet.






Michael
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1
Reputation: ravi_be is an unknown quantity at this point 
Solved Threads: 0
ravi_be ravi_be is offline Offline
Newbie Poster

Re: dynamically generated textboxes & radio buttons php, insert into db

 
0
  #3
Jun 24th, 2005
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")
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1
Reputation: tara is an unknown quantity at this point 
Solved Threads: 0
tara tara is offline Offline
Newbie Poster

Re: dynamically generated textboxes & radio buttons php, insert into db

 
0
  #4
Sep 2nd, 2005
hello,
Originally Posted by seemajanardhan
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC