944,198 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 30019
  • PHP RSS
Mar 26th, 2005
0

dynamically generated textboxes & radio buttons php, insert into db

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
seemajanardhan is offline Offline
1 posts
since Mar 2005
Mar 27th, 2005
0

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

Quote ...
html textfield array values
Is this a creation of your own? Because I haven't seen it yet.






Michael
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
pcschrottie is offline Offline
204 posts
since Dec 2004
Jun 24th, 2005
0

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

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")
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ravi_be is offline Offline
1 posts
since Jun 2005
Sep 2nd, 2005
0

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

hello,
Quote 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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tara is offline Offline
1 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Dummy asks: how can i?
Next Thread in PHP Forum Timeline: PHP Installation Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC