PHP mysqli提交选定的内容并重置其他行

时间:2018-10-19 11:36:29

标签: php mysqli

下面是一个简化的表,但实际上有很多行。在前端,有一些选择框,每个选择框都回显所有标题,作为可能的选项。如果我使用复选框名称“ one_six”选择“交换我”选项以“交换到此”,然后提交,则该行的main_nav值将更改,“交换我”将重置为0。

有一些选择框,当我单击“提交”时,不仅main_nav应该在正确的行上更新为正确的数字,表中未被选择为选项的任何行都应设置为0。 / p>

目前,由于某种原因它不会提交并进行更新。我没有错误。我不知道如何重设所有现有行(如果未通过任何选择框选择并提交)。有任何想法吗?我在下面包含了我的代码。

+----+--------------------------+----------+
| 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();     
?>

0 个答案:

没有答案