【问题标题】:How to send an array of values into database using codeigniter如何使用codeigniter将一组值发送到数据库
【发布时间】:2017-01-05 05:08:28
【问题描述】:

需要将 html 元素数组发送到数据库中的不同行中 下面给出的是html代码。

<form action="#" method="post">
<input type="text" name="user[]" />
<input type="text" name="user[]" />
<input type="text" name="user[]" />
<input type="submit" value="submit" >
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{ 
foreach($_POST['user'] as $key => $value)
{
echo $key." has the value = ". $value."<br>";
}
}
?>

【问题讨论】:

  • 从操作中移除井号。

标签: codeigniter mysqli


【解决方案1】:

你可以这样实现....

<?php

$this->load->database();
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{ 
    foreach($_POST['user'] as $key => $value)
    {
        $data = array('user'=>$value);
        $this->db->insert('table_name',$data); //Generated query >> INSERT INTO table_name(user) VALUES ('$value');
    }
}
?>

【讨论】:

  • 是否可以发送到表的不同行
  • print_r($_POST['user']); 的输出是什么。它将插入不同的行。
猜你喜欢
  • 2020-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-10
  • 2020-08-25
  • 2018-08-22
  • 2015-07-03
  • 1970-01-01
相关资源
最近更新 更多