php - Prevent submit button from duplicate in form -
i'm generating form questions stored in database. don't understand how can prevent submit button duplicate every row (question)? want 1 submit button in end of form.
// generate questions $query = "select * 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/>'; }
you'll need move submit button outside of while
loop. (as side note, prefer alternative syntax control structures.)
<? // generate questions $query = "select * 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; ?>
Comments
Post a Comment