Php 无法在具有PDO的表中插入行

Php 无法在具有PDO的表中插入行,php,pdo,Php,Pdo,我想使用PDO将一些数据插入表中。我查找了一些示例,发现我需要使用函数prepare、bind和execute,但是我无法在代码中找出我做错了什么,因为它没有插入任何内容,查询或php代码中也没有错误 if($_POST){ $account = $_POST['account']; $password = $_POST['password']; $phone = $_POST['phone']; $email = $_PO

我想使用PDO将一些数据插入表中。我查找了一些示例,发现我需要使用函数prepare、bind和execute,但是我无法在代码中找出我做错了什么,因为它没有插入任何内容,查询或php代码中也没有错误

    if($_POST){

    $account    = $_POST['account'];
    $password   = $_POST['password'];
    $phone      = $_POST['phone'];
    $email      = $_POST['email'];

    $stmt =     'INSERT INTO employer(account, password, phone, email) VALUES(:account, :password, :phone, :email)';
    $stmt = $conn->prepare($stmt);

    $stmt->bindParam(':account', $account, PDO::PARAM_STR,100);
    $stmt->bindParam(':password',$password, PDO::PARAM_STR,100);
    $stmt->bindParam(':phone', $phone, PDO::PARAM_STR,100);
    $stmt->bindParam(':email', $email, PDO::PARAM_STR,100);

    if ($stmt->execute(array('account'  => $account,
                             'password' => $password,
                             'phone'    => $phone,
                             'email'    =>$email
                             )
                        )
        ){
    echo "success";
    }else{
        echo "error";
    }

}

@jeroen检测到错误,我绑定了两次。因此,我可以在execute语句之前绑定,也可以将数组作为参数发送,而不是两者都绑定

$stmt = $pdo->prepare('
INSERT INTO employer
(account, password, phone, mail)
values (:account, :password, :phone, :mail)');

  $stmt->execute( 
            array(':account'    => $account, 
                  ':password'   => md5($password), 
                  ':phone'      => $phone,
                  ':mail'        => $email
                  )
            );

  if ($pdo->lastInsertId())
    return true;
  else
   return false;

错误报告/检查说明了什么?为什么要使用bindParam和array?在这里,请仔细阅读要绑定的主题两次,要么在execute语句之前绑定,要么将数组作为参数发送,而不是两者都发送。您应该添加错误处理,例如,当出现问题时让PDO抛出异常。@jeroen怀疑他们是否知道异常是什么。也怀疑他们在读我们。也怀疑他们读过手册。@jeroen我知道;我的语法/拼写/水晶球一点也不清楚,我的朋友bad@jeroen除非你也投票决定结束,否则请你主持会议并回答问题好吗?或者如果你不愿意的话