只在数组的最后一行输入文本类型


Input text type into array only last row

我有一些text input,可以编辑一些主题的值,如下所示:

while($row = mysql_fetch_row($result2))
    {
       echo "<tr><td>" . $row['ID'] . "</td><td>" . $row['Name'] . "</td><td>" . $row['Status'] . 
       "</td><td><input type='"text'" size='"4'" id='"editmath[]'" name='"editwater'" value=" . $row['math'] . ">
       </td><td><input type='"text'" size='"4'" id='"editeng[]'" name='"editfod'" value=" . $row['english'] .  ">
       </td><td><input type='"text'" size='"4'" id='"editscie[]'" name='"editmob'" value=" . $row['science'] . ">
        }
<Input type="Submit" value=" Next " name="submit_edit">

在PHP中,我有这样的代码:

if (isset($_GET['submit_edit'])) {
        $math[] = $_GET['editmath'];
        $eng[] = $_GET['editeng'];
        $scie[] = $_GET['editscie'];
        sql = "UPDATE student SET math = $math, english = $eng, science = $scie";
        $query = mysql_query($sql);
}

但当我尝试print_rmatheng时,它们只保存了最后一行。如何解决这个问题?

Desired Output :
Math    English   Science
4       3        2
7       8        10
3       5        12

这里的名称与输入框重复,这就是出现此问题的原因:

1) 将输入框的名称声明为数组,并在php循环中通过该数组存储数据:

2) 使用POST表单而不是GET表单类型:

3) 如果你想更新记录,你还需要传递id和所有数据

前任。

while($row = mysql_fetch_row($result2))
    {
       echo "<tr><td>" . $row['ID'] . "</td><td>" . $row['Name'] . "</td><td>" . $row['Status'] . 
       "</td><td><input type='"text'" size='"4'" id='"editmath[]'" name='"editwater[]'" value=" . $row['math'] . ">
       </td><td><input type='"text'" size='"4'" id='"editeng[]'" name='"editfod[]'" value=" . $row['english'] .  ">
       </td><td><input type='"text'" size='"4'" id='"editscie[]'" name='"editmob[]'" value=" . $row['science'] . ">
        }
<Input type="Submit" value=" Next " name="submit_edit">

PHP

if (isset($_POST['submit_edit'])) {
        for($i = 0; i < sizeof($_GET['editmath']) ; $i++) {
           $math = $_POST['editmath'][$i];
           $eng = $_POST['editeng'][$i];
           $scie = $_GET['editscie'][$i];
           $sql = "UPDATE student SET math = $math, english = $eng, science = $scie";
           $query = mysql_query($sql);
        }
}