【发布时间】:2021-09-13 19:11:10
【问题描述】:
如果用户未回答问题,我需要获得所有问题的答案。为这个问题的结果在数据库上设置 null。
<form action="forms/handle-questions.php" method="post">
<?php foreach ($questions $key => $question) : ?>
<div class="row">
<?= $question['question'] ?>
</div>
<div class="form-check ">
<input class="form-check-input" type="radio" name="radio_<?= $question['id'] ?>"
value="good">
<label class="form-check-label"> good</label>
</div>
<div class=" form-check ">
<input class="form-check-input" type="radio" name="radio_<?= $question['id'] ?>"
value="medium">
<label class="form-check-label" >medium</label>
</div>
<div class="form-check ">
<input class="form-check-input" type="radio" name="radio_<?= $question['id'] ?>"
value="weak">
<label class="form-check-label">weak</label>
</div>
<?php endforeach ?>
<button type="submit" name="handle_questions">Done</button>
</form>
对于每个问题,我已经得到了带有 id 的答案的问题,但我需要其他答案并将其设置为 null。
foreach ($_POST as $key => $record) {
if (strpos($key, 'radio_') !== false) {
$question_id = str_replace('radio_', '', $key);
// here get the question id and insert in database
}
}
我真的不知道输出会是这样的
Array
(
[radio_1] => good
[radio_2] => medium
[radio_3] => medium
[radio_4] => medium
[radio_5] => null
[radio_6] => medium
[radio_7] => null
[radio_8] => null
)
【问题讨论】:
-
请提供所需的o/p
-
我编辑了这样做可以帮助您理解我吗?
-
试一试答案,让我们知道。
标签: php html mysql forms form-submit