how to retrieve values from database to a html form for user

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
RajkumarLA
Forum Newbie
Posts: 1
Joined: Wed May 15, 2013 2:24 am

how to retrieve values from database to a html form for user

Post by RajkumarLA »

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.

Code: Select all

$sql="SELECT * FROM questions, answers WHERE answers.qid = questions.qid";
$result=mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
  if ($row['qtext'] != $lastQuestion) {
    echo "<p>" . $row['qtext'] . "</p><br />";
	$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...
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: how to retrieve values from database to a html form for

Post by requinix »

Name the answer buttons "answer[$qid]", then $_POST["answer"] will be an array. Then store those values in a table.
Post Reply