通过HTML表单向数据库添加问题时选择正确的答案
I have a form which has the question and 4 answers (it's a quiz), I tried to comment on https://stackoverflow.com/a/29280091/6482242 but I don't have enough reputation yet. This is very similar to what I have (as well as How to set the correct answer via checkbox? ).
The layout that I have is:
<label for="question_text">Question Text:</label>
<textarea title="Insert Question Text" name="question_text"></textarea>
<h4>Check Correct answer -></h4>
<input type="radio" name="correct_answer_flag" value="1">
<label for="correct_answer_flag, answer_1">Answer One:</label>
<input type="text" title="Enter Answer" name="answer_1" />
<br />
<br />
<input type="radio" name="correct_answer_flag" value="1">
<label for="correct_answer_flag, answer_2">Answer Two:</label>
<input type="text" title="Enter Answer" name="answer_2" />
<br />
<br />
<input type="radio" name="correct_answer_flag" value="1">
<label for="correct_answer_flag, answer_3">Answer Three:</label>
<input type="text" title="Enter Answer" name="answer_3" />
<br />
<br />
<input type="radio" name="correct_answer_flag" value="1">
<label for="correct_answer_flag, answer_4">Answer Four:</label>
<input type="text" title="Enter Answer" name="answer_4" />
<br />
<br />
<input type="submit" value="Submit Question" name="question_submit" />
There is some PHP in the background to grab these and put them into a database, but I need to know please what the correct syntax is to link a radio button to a text input?
Thanks in advance :D
我有一个有问题和4个答案的表格(这是一个测验),我试着评论 https://stackoverflow.com/a/29280091/6482242 但我还没有足够的声誉。 这与我的非常相似(以及如何通过复选框设置正确答案?)。 p>
我的布局是: p>
&lt; label for =“question_text”&gt;问题文本:&lt; / label&gt;
&lt; textarea title =“插入问题文本”name =“question_text”&gt;&lt; / textarea&gt;
&lt; h4&gt;检查正确答案 - &gt;&lt; / h4&gt;
&lt; input type =“radio” name =“correct_answer_flag”value =“1”&gt;
&lt; label for =“correct_answer_flag,answer_1”&gt;答案一:&lt; / label&gt;
&lt; input type =“text”title =“Enter Answer”name = “answer_1”/&gt;
&lt; br /&gt;
&lt; br /&gt;
&lt; input type =“radio”name =“correct_answer_flag”value =“1”&gt;
&lt; label for =“correct_answer_flag, answer_2“&gt;答案二:&lt; / label&gt;
&lt; input type =”text“title =”输入答案“name =”answer_2“/&gt;
&lt; br /&gt;
&lt; br /&gt; \ n&lt; input type =“radio”name =“correct_answer_flag”value =“1”&gt;
&lt; label for =“correct_answer_flag,answer_3”&gt;答案三:&lt; / label&gt;
&lt; input type =“text” title =“输入答案”name =“answer_3”/&gt;
&lt; br /&gt;
&lt; br /&gt;
&lt; input type =“radio”name =“correct_a nswer_flag“value =”1“&gt;
&lt; label for =”correct_answer_flag,answer_4“&gt;答案四:&lt; / label&gt;
&lt; input type =”text“title =”输入答案“name =”answer_4“ /&gt;
&lt; br /&gt;
&lt; br /&gt;
&lt; input type =“submit”value =“提交问题”name =“question_submit”/&gt;
code> pre>
后台有一些PHP要抓住这些并将它们放入数据库,但我需要知道将单选按钮链接到文本输入的正确语法是什么? p> \ n
提前致谢:D p>
div>
You should change the values of radio buttons and then store its value to a separate column in table with column something like correct_answer
<label for="question_text">Question Text:</label>
<textarea title="Insert Question Text" name="question_text"></textarea>
<h4>Check Correct answer -></h4>
<input type="radio" name="correct_answer_flag" value="1">
<label for="correct_answer_flag, answer_1">Answer One:</label>
<input type="text" title="Enter Answer" name="answer_1" />
<br />
<br />
<input type="radio" name="correct_answer_flag" value="2">
<label for="correct_answer_flag, answer_2">Answer Two:</label>
<input type="text" title="Enter Answer" name="answer_2" />
<br />
<br />
<input type="radio" name="correct_answer_flag" value="3">
<label for="correct_answer_flag, answer_3">Answer Three:</label>
<input type="text" title="Enter Answer" name="answer_3" />
<br />
<br />
<input type="radio" name="correct_answer_flag" value="4">
<label for="correct_answer_flag, answer_4">Answer Four:</label>
<input type="text" title="Enter Answer" name="answer_4" />
<br />
<br />
<input type="submit" value="Submit Question" name="question_submit" />
And in that column just store the number of the selected Radio. So with each question, you will be storing 4 options, and among those 4 there will be one correct answer and its index will be stored in a separate table where you store you answer options.