插入多个相同的字段名称codeigniter

时间:2018-12-02 14:07:35

标签: php codeigniter

<input name="fldWorkHistoryCompanyName[]" type="text" class="form-control" placeholder="1023456789" value="">

<input name="fldWorkHistoryCompanyName[]" type="text" class="form-control" placeholder="1023456789" value="">

<input name="fldWorkHistoryCompanyName[]" type="text" class="form-control" placeholder="1023456789" value="">

<input name="fldWorkHistoryCompanyName[]" type="text" class="form-control" placeholder="1023456789" value="">

**如何使用codeigniter *

插入此值

1 个答案:

答案 0 :(得分:2)

超全局$_POST['fldWorkHistoryCompanyName']将是一个数组,其中每个值都是文本输入的内容。捕获数组并遍历数组以完成所需的操作。

$names = $this->input->post('fldWorkHistoryCompanyName');
foreach ($names as $name)
{
    if(empty($name))
    {
        // whatever you need to do when no data was sent
        // if you want to ignore empty inputs then all you need is
        continue;
    }
    else
    {
        //save $name to the database
    }