Get the values of 2 HTML input tags having the same name using PHP

后端 未结 4 1658
旧时难觅i
旧时难觅i 2021-01-21 00:41

Suppose I have the following table:

4条回答
  •  -上瘾入骨i
    2021-01-21 01:07

    When you have repeated names, you have to give them array-style names:

    
    

    When you do this, $_POST['id'], $_POST['latitude'], and $_POST['longitude'] will be arrays containing the values.

    Your form processing code can then iterate over these:

    for ($i = 0; $i < count($_POST['id']); $i++) {
      if (isset($_POST['latitude'][$i], $_POST['longitude'][$i])) { // Make sure both are filled in
        // Do stuff with this row of the form
      }
    }
    

提交回复
热议问题