我有这个数组,其中包含来自 html 表单的数据,并且我希望将这个数组插入到处理INSERT
mysql 查询的 PHP 函数中。
如何将我的数组声明为 PDO
if (isset($_POST['submit'])); {
$_POST['name'];
$_POST['age'];
$myarray= array();
foreach ($_POST as $key => $value){
$myarray[$key] = $value;
}
whatever($myarray);
}
functions whatever($myarray) {
$sql=$db->prepare("INSERT INTO `user`(`name`, `age`) VALUES (:name,:age)");
foreach($myarray as $row=>$value){
$sql->bindValue(array($myarray)){
}
$sql->execute();
}
为忘记错误道歉。
这就是我得到的
Warning: PDOStatement::bindValue() expects at least 2 parameters, 1 given in C:\Web\xampp\htdocs\submit.php on line 36
Warning: PDOStatement::bindValue() expects at least 2 parameters, 1 given in C:\Web\xampp\htdocs\submit.php on line 36
Warning: PDOStatement::bindValue() expects at least 2 parameters, 1 given in C:\Web\xampp\htdocs\submit.php on line 36
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound' in
C:\Web\xampp\htdocs\submit.php:38 Stack trace: #0
C:\Web\xampp\htdocs\submit.php(38): PDOStatement->execute() #1
C:\Web\xampp\htdocs\submit.php(12): register(Array) #2 {main} thrown in
C:\Web\xampp\htdocs\submit.php on line 38