PHP在具有多个表单输入的同一列中添加数据

时间:2019-02-14 13:52:04

标签: php mysql

我有一个带有v_name和l_value列的表,我必须从

添加数据
PATH = /home/project/bin:/home/project/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

我的表格是

    id       v_name    l_value
---------- ---------- ----------
1          SITE_URL    localhost/sitename

2          SITE_EMAIL  email@email.com

我有2个输入,但我希望我的数据添加到单个表列中。

1 个答案:

答案 0 :(得分:1)

您应在[]属性中使用name表示法:

<label>Page Url</label>
<input type="hidden" placeholder="Enter Page Title" class="form-control"  name="v_name[]" id="SITE_URL" value="SITE_URL" required>
<input type="text" placeholder="Enter Page Title" class="form-control"  name="l_value[]" id="SITE_URL" value="" required>
</div>

<div class="form-group">
<label>Page Email</label>
<input type="hidden" placeholder="Enter Page Title" class="form-control" name="v_name[]" id="SITE_EMAIL" value="SITE_EMAIL" required>
<input type="text" placeholder="Enter Page Title" class="form-control"  name="l_value[]" id="SITE_EMAIL" value="" required>
</div>

在服务器端,您可以通过$_POST数组访问值(如果请求方法为POST):

foreach ($_POST['v_name'] as $key => $name) {
    echo $name . ' and ' . $_POST['l_value'][$key];
}