PHP不会插入数据库

时间:2016-01-06 22:52:07

标签: php mysql pdo insert

我尝试在参数周围加上引号,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);
}

0 个答案:

没有答案