0
我想在数据库中一一提交单选按钮中给出的答案,但是我不知道如何。我尝试了一些事情,但没有成功。
这是为了进行调查,这就是为什么我要保存问题的答案的原因。有关代码的问题是代码中的for循环。
我尝试更改我的Sql查询,但没有帮助
<form method="POST">
<?php
include '../include/db_conn.php';
$url = $_GET['surveyUrl'];
$sqlGetSurvey = 'SELECT * FROM `survey_info` WHERE `survey_url`="'. $url .'"';
$resultGetSurvey = mysqli_query($conn, $sqlGetSurvey);
if ($resultGetSurvey ->num_rows > 0) {
while ($row = $resultGetSurvey-> fetch_assoc()) {
$surveyId = $row['survey_id'];
$sqlGetQuestion = 'SELECT * FROM `survey_questions` WHERE `survey_id`="'. $surveyId .'"';
$sqlGetSurvey = 'SELECT * FROM `survey_info` WHERE `survey_id`="'. $surveyId .'"';
$resultGetQuestion = mysqli_query($conn, $sqlGetQuestion);
$resultGetSurvey = mysqli_query($conn, $sqlGetSurvey);
if ($row = mysqli_fetch_assoc($resultGetSurvey)) {
$text_color = $row['survey_text_color'];
$background_color = $row['survey_background_color'];
$theme_color = $row['survey_theme_color'];
}
if ($resultGetQuestion ->num_rows > 0) {
while ($row = $resultGetQuestion-> fetch_assoc()) {
$questionId = $row['question_id'];
$count = 'A';
$yuyu = "<ul class='list-group mx-auto mt-3'>
<li class='list-group-item'>". $row['question'] ."</li>";
$sqlGetAnswers = 'SELECT * FROM `survey_question_answers` WHERE `question_id`='. $questionId .'';
$resultGetAnswers = mysqli_query($conn, $sqlGetAnswers);
if ($resultGetAnswers ->num_rows > 0) {
while ($row = $resultGetAnswers-> fetch_assoc()) {
$yuyu .= "<li class='list-group-item'><span class='badge badge-light main-color-bg'>". $count .". <input type='radio' name='$questionId' value='$count'></span> ". $row['answer'] ."</li>";
++$count;
}
}
echo '</ul>';
echo $yuyu;
}
}
}
}
if(isset($_POST['submit']))
{
for($x= 1; $x <= $questionId; $x++){
$antwoord = $_POST[$questionId];
$sql = "INSERT INTO survey_answers (question_id, survey_id, answers) VALUES ('$questionId', '$surveyId', '$antwoord')";
}
}
?>
<input type="submit" name="submit" value="Show answer" class="btn btn-primary mb-3 mt-3">
我希望它在我的数据库中一一插入
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。