【问题标题】:Add rows in the database table depending on the array [duplicate]根据数组在数据库表中添加行[重复]
【发布时间】:2019-06-22 18:31:47
【问题描述】:

请告诉我有第 n 个输入量。它总是不同的,可能是 1,也可能是 20。代码如下所示:

<form action="/1.php" method="post">
<input type="text" value="1" name="more[1]">
<input type="text" value="2" name="more[2]">
<input type="text" value="3" name="more[3]">
<input type="text" value="4" name="more[4]">
<input type="text" value="5" name="more[5]">
<input type="submit">
</form>

如何将我们在表单中输入的行数添加到数据库表中?也就是说,应该在表中创建 5 条记录。提前谢谢你。

【问题讨论】:

  • 我在任何地方都找不到 php 代码!您可能忘记粘贴了吗?
  • 检查 $_POST 数组

标签: php html


【解决方案1】:

在您的操作页面上在您的输入数组上创建一个循环

试试这个

foreach($_POST['more'] as $value){
   $query = mysqli_query('Insert Into TableName Values("",$value)');
}

希望这个想法对您有所帮助

【讨论】:

  • 使用 mysqli_close($conn);和 header() 在循环之外
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-13
  • 2013-07-24
  • 2012-06-02
  • 2021-05-06
  • 1970-01-01
相关资源
最近更新 更多