dongzaijiao4863 2014-08-17 21:24
浏览 55
已采纳

防止表单中的重复提交按钮

I'm generating a form with all questions stored in the database. I don't understand how I can prevent the submit button from duplicate itself for every row (question)? I only want one submit button in the end of the form.

// generate all questions
$query = "SELECT * FROM questions";
$result = @mysqli_query($con, $query);

if ($result) {
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {

    $body = $row['question_body'];
    $question_id = $row['question_id'];

    echo '  
        <tr>
            <form action="insert.php" method="POST">
                <td><input type="hidden" name="question_id" value="'.$question_id.'">'.$question_id, $body.'</td>
                <td><input type="radio" name="answer_value" value="1"></td>
                <td><input type="radio" name="answer_value" value="2"></td>
                <td><input type="radio" name="answer_value" value="3"></td>
                <input type="submit">
         </tr>
             </form>
                        <br/>';
}
  • 写回答

2条回答 默认 最新

  • dongzhu0327 2014-08-17 21:32
    关注

    You'll need to move the submit button outside of the while loop. (As a side note, I prefer the alternative syntax for control structures.)

    <?
    // Generate all questions
    $query = "SELECT * FROM questions";
    $result = @mysqli_query($con, $query);
    if ($result) :
    ?>
    <form action="insert.php" method="POST">
        <table>
    <?
        while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) :
            $body = $row['question_body'];
            $question_id = $row['question_id'];
    ?>
            <tr>
                <td><input type="hidden" name="question_id" value="<? echo $question_id ?>"><? echo $question_body ?></td>
                <td><input type="radio" name="answer_value" value="1"></td>
                <td><input type="radio" name="answer_value" value="2"></td>
                <td><input type="radio" name="answer_value" value="3"></td>
            </tr>
    <?
        endwhile;
    ?>
            <tr>
                <input type="submit">
            </tr>
        </table>
    </form>
    <?
    endif;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应