I have a simple table "Exams" with the columns id, title and a form with a variable amount of exam input fields.
But when one submit the form the last value will be saved triple times.
I suppose it's because of the $sql_insert statement with the same value.
How can i change the code that the different values are submitted in that $sql_insert statement?
echo '<form action="" method="post">';
for ($i = 1; $i <= $student['passed_exams']; ++$i) {
echo '<label>Exams '.$i.' :</label>';
echo '<input type="text" id="id['.$i.']" name="title" placeholder="passed Exam" />';
echo '<br />';
}
echo '<input type="submit" value=" Submit " name="submit" /></form>';
if (isset($_POST['submit'])) {
for ($i = 0; $i < $student['passed_exams']; ++$i) {
$sql_insert = "INSERT INTO exams (title) VALUES ('".$_POST['title']."')";
$dbConnection->query($sql_insert);
}
$dbConnection->close();
}