Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.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_Pdo - Fatal编程技术网

如何在php中插入多个选定数据?

如何在php中插入多个选定数据?,php,mysql,pdo,Php,Mysql,Pdo,我试图在数据库中选择多个数据,并插入多个数据。 这是我的问题 多选: <select name="sec_id[]" data-live-search="true" class="selectpicker form-control border-input" style="text-align-last:center;" title="Select Section" required multiple> <?php $stmtSection = $crud->runQu

我试图在数据库中选择多个数据,并插入多个数据。 这是我的问题

多选:

<select name="sec_id[]" data-live-search="true" class="selectpicker form-control border-input"
 style="text-align-last:center;" title="Select Section" required multiple>
<?php
$stmtSection = $crud->runQuery('SELECT * FROM tbl_section ORDER BY sec_id DESC');
$stmtSection->execute();
while($rowSection=$stmtSection->fetch(PDO::FETCH_ASSOC))
{
  print("<option value='".$rowSection['sec_id']."'>".$rowSection['section']."</option>");
}
?>
</select>
向数据库插入多个数据:(我在哪里得到错误)

功能:

    public function addAccount($account,$new_password,$access,$query,$section,$sec_id)
    {
      $stmt = $this->conn->prepare($query);
      $stmt->execute(array(":username"=>$account,
                           ":password"=>$new_password,
                           ":access_type"=>$access,
                           ":section"=>$section,
                           ":sec_id"=>$sec_id));

      return $stmt;
    }
我对insert有问题。
请帮我查一下我的问题。提前谢谢。

您有什么问题?如果要插入多行,则在C:\xampp\htdocs\PDO\Files Server\Main\add版主帐户中运行多个
execute
callsUndefined variable:section应该很简单。php@NicoHaase这是错误井,然后很明显该做什么:错误消息中甚至应该有一个行号,告诉您变量
$section
没有在任何地方定义,而是可以访问的
$query="INSERT INTO tbl_login(username,password,access_type,section,sec_id) 
        VALUES(:username, :password, :access_type, :section, :sec_id)";
if($crud->addAccount($account,$new_password,$access,$query,$section,$sec_id))
    public function addAccount($account,$new_password,$access,$query,$section,$sec_id)
    {
      $stmt = $this->conn->prepare($query);
      $stmt->execute(array(":username"=>$account,
                           ":password"=>$new_password,
                           ":access_type"=>$access,
                           ":section"=>$section,
                           ":sec_id"=>$sec_id));

      return $stmt;
    }