Below is a simplified table, but in reality there are quite a lot of rows. On the front-end there are some select boxes where each one echo out all the headlines as a possible option. If I select the option of 'swap me' using the checkbox name of 'one_six' to 'swap to this' then submit, the value of main_nav for that row would change and the 'swap me' would reset to 0.
There are a few select boxes and when I hit submit not only should the main_nav update on the correct row to the correct number, any row in the table that hasn't been selected as an option should be set to 0.
At the moment it won't submit for some reason and update. I get no errors. I have no idea how to reset all the existing rows if not selected and submitted by any select box. Any ideas? I have included my code below.
+----+--------------------------+----------+
| id | headline | main_nav |
+----+--------------------------+----------+
| 1 | a cool headline | 17 |
+----+--------------------------+----------+
| 2 | just another hadline | 15 |
+----+--------------------------+----------+
| 3 | some other fun thing | 11 |
+----+--------------------------+----------+
| 4 | swap me | 16
+----+--------------------------+----------+
| 5 | here is another headline | 12 |
+----+--------------------------+----------+
| 6 | headline 6 | 14 |
+----+--------------------------+----------+
| 7 | headline 7 | 13 |
+----+--------------------------+----------+
| 8 | swap to this | 0 |
<?php
require_once("../db/db.php");
if (isset($_POST['submit'])) {
$sql = $conn->prepare("UPDATE pages SET main_nav=? WHERE id=?");
$one_one = $_POST['one_one'];
$one_two =$_POST['one_two'];
$one_three = $_POST['one_three'];
$one_four = $_POST['one_four'];
$one_five= $_POST['one_five'];
$one_six = $_POST['one_six'];
$one_seven = $_POST['one_seven'];
$sql->bind_param("iiiiiii", $one_one, $one_two, $one_three, $one_four, $one_five, $one_six, $one_seven);
if($sql->execute()) {
$success_message = "Edited Successfully";
} else {
$error_message = "Problem in Editing Record";
}
}
$sql = "SELECT * FROM pages";
$result = $conn->query($sql);
$conn->close();
?>