Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 尝试使用动态创建的表单更新数据库中的日期_Php_Mysql - Fatal编程技术网

Php 尝试使用动态创建的表单更新数据库中的日期

Php 尝试使用动态创建的表单更新数据库中的日期,php,mysql,Php,Mysql,因此,我创建了一个管理页面,根据数据库中的用户数量创建X个表单,每个表单旁边都有一个提交按钮,用于提交对数据库中日期的更改。我的问题是,当我想得到发布内容的价值时,我无法从发布的内容中准确提取我需要的内容。它被保存到一个名为的数组中,当我打印该数组时,我得到的正是我想要的,即: [1] => "whatever date they typed in" (obviously the 1 changes depending on which item they changed the

因此,我创建了一个管理页面,根据数据库中的用户数量创建X个表单,每个表单旁边都有一个提交按钮,用于提交对数据库中日期的更改。我的问题是,当我想得到发布内容的价值时,我无法从发布的内容中准确提取我需要的内容。它被保存到一个名为的数组中,当我打印该数组时,我得到的正是我想要的,即:

  [1] => "whatever date they typed in" 
  (obviously the 1 changes depending on which item they changed the date of)
我需要能够通过以下方式查询我的数据库:

  UPDATE users SET subdate="whatever they typed in" WHERE id="the array reference number"
我确切地知道我需要做什么,我只是不熟悉SQL,因为我想,所以任何帮助将不胜感激。提前谢谢

参考代码:

<div class="form-section grid12" id="changedates">
<h1>Change Dates</h1>
    <?php
          $query = mysql_query("SELECT * FROM users WHERE admin='y'");
    ?>
    <table>
    <?php
      while($row = mysql_fetch_assoc($query)) {
    ?>
    <tr>
      <td>
        <h5><?php echo $row['displayname'];?></h5>
      </td>

      <td>
        <form action="" method="POST">
          <input type="text" name="subdate[<? echo $row['id'] ?>]" value="<?php echo $row['submissiondate'];?>">
          <input type="text" name="nextupdate[<? echo $row['id'] ?>]" value="<?php echo $row['nextupdate'];?>">
      </td>

      <td>
          <input type="submit" value="Set Date" name="setdate">
        </form>
      </td>
  <?php
    }
  ?>
    </table>

</div>

更改日期

你可以用foreach

foreach ($_POST[nextupdate] as $rowId => $time)
    {
    // do db update
    }
编辑:刚刚意识到每个表单有多个输入

为什么不使用数组名称命名每个输入:

<input type="text" name="form_data[<?= $row_id ?>][subdate]">
<input type="text" name="form_data[<?= $row_id ?>][nextupdate]">
foreach ($_POST[form_data] as $rowId => $values)
    {
    $subdate = $values[subdate];
    $nextupdate = $values[nextupdate];

    // do SQL stuff
    }