Im trying to build a dynamic form that uses questions in the database as the form fields.
In my database, I have a table named questions, with "Question 1" "Question 2" and "Question 3". They are all yes or no questions.
Here is the code the correctly retrieves the info and builds my dynamic form:
<?php require_once 'includes/session.php';
include 'includes/functions.php';
$questions = mysqli_query($dbconn, "SELECT * FROM rules");
?>
<form action="submit.php">
<?php
while($show= mysqli_fetch_array($questions))
{ ?>
<label id="<?php echo $show['id']; ?>"><?php echo $show['Rule_Name']; ?></label><input name="<?php echo $show['id']; ?>" type="radio" value="Yes">Yes</input><input name="<?php echo $show['id']; ?>" type="radio" value="No">No</input><br>
<?php } ?>
<input name="submit" type="submit" value="submit" />
</form>
Because all these fields are dynamically generated, how would I structure the submit.php page to store all the values of the submitted form so that I may insert into my database.
Normally I would write my code like this when I know the values:
<?php
if($_POST) {
$answer1 = $_POST['question1'];
and so forth.
Since the values are unknown (don't know what questions are going to be added in the future) how would I build that to store the values of all the answers?
I spent some time googling, but didnt come across anything noteworthy. It may be my phrasing of the question was off.