how to retrieve values from database to a html form for users to select ?

Hi, i am displaying questions with multiple answers from the database to users. he has to participate in the contest.

i have stored questions in questions table. qid, qtext.
answers in answers table. aid,atext,cans (correct ans)

i have displayed the questions and multiple answers from database. like this…

What is capital of India
1.Chennai (radio button)
2.Bangalore (radio button)
3.Delhi (radio button)

What is capital of England
1.London (radio button)
2.Paris (radio button)
3.Madrid (radio button)

This is the PHP code.

[php]$sql=“SELECT * FROM questions, answers WHERE answers.qid = questions.qid”;

while ($row = mysql_fetch_array($result)) {
if ($row[‘qtext’] != $lastQuestion) {
echo “

” . $row[‘qtext’] . “

$lastQuestion = $row[‘qtext’];
echo “<input type=‘radio’ name=’”.$row[‘qid’]."’ value=’".$row[‘aid’]."’ />".$row[‘atext’];

i want to store the users result into the database. how can i make this as form for user can select answers and submit… so i can store the results in the database. i am new to php… please help…

You will need a third table that stores the user id with the qid and aid

this is the form.
[php]echo “”;
$sql=“SELECT * FROM cquestions”;
while ($row = mysql_fetch_array($result)) {
echo “

” . $row[‘cqtext’] . “

$sql2=“SELECT * FROM canswers where cqid=”.$row[‘cqid’];
echo “<input type=‘radio’ name=’”.$row[‘cqid’]."’ value=’".$row2[‘ccans’]."’ />".$row2[‘aatext’]; }
/echo “”;/
echo “” ?>[/php]

after clicking the submit button. it will go to checkresults.php page. in that page how to retrieve the values using $_POST array???

Sponsor our Newsletter | Privacy Policy | Terms of Service