我尝试在参数周围加上引号,var_dumps在直接输入数据库时可以正常工作。
function insertdata($pdo, $arr){
unset($_POST['submit']);
$query = '';
foreach ($arr as $inner) {
if ($inner['COLUMN_NAME'] == 'title')
$query .= $inner['COLUMN_NAME'];
else $query .= ','.$inner['COLUMN_NAME'];
}
$values = '"'.implode('","', $_POST).'"';
$stmt1 = $pdo->prepare('INSERT INTO :table (:query)
VALUES (:val);');
$criteria = [
'table' => strtolower($_GET['section']),
'query' => $query,
'val' => $values
];
$stmt1->execute($criteria);
}