PDO - 没有错误,但没有数据插入

时间:2016-10-30 14:34:36

标签: php mysql pdo

简:我想用PDO在MySQL数据库中插入数据。 问题:数据库中没有数据,也没有错误消息。我做错了什么?

我希望有人可以快速帮助我。 谢谢。

<?php
if(isset($_POST['absenden'])) {

  //VAR's
    $user_name = $_POST['user_name'];
    $user_email = $_POST['user_email'];
    $user_mc_name = $_POST['user_name_minecraft'];
    $user_tw_name = $_POST['user_name_twitter'];
    $user_age = $_POST['user_age'];
    $user_bio1 = $_POST['user_bio_about'];
    $user_bio2 = $_POST['user_bio_experiences'];
    $user_bio3 = $_POST['user_bio_references'];
    $user_bio4 = $_POST['user_bio_why'];
    $user_job = $_POST['user_job'];
    $user_interest = $_POST['user_interest'];

    try {
      $db = new PDO('mysql:host=localhost;dbname=apps;', 'root', '');
      $sql = $db->prepare("INSERT INTO applications (name, email, mc_name, tw_name, age, bio_about, bio_experiences, bio_references, bio_why, job) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
      $sql->execute(array($user_name, $user_email, $user_mc_name, $user_tw_name, $user_age, $user_bio1, $user_bio2, $user_bio3, $user_bio4, $user_job));
      echo "All data catched.";
    }
    catch (Exception $e) {
      echo "Error. Your Application wasn't send.";
      echo $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }
  }

 ?>

0 个答案:

没有答案