数据库插入不起作用(MySQL,PHP)


Database insert not working (MySQL, PHP)

我有这个PHP,基本上是用来将电子邮件和密码插入SQL数据库:

<?php  
error_reporting(E_ALL ^ E_STRICT);
require "database.php";
$message = '';
  if (!empty($_POST["email"]) &&!empty($_POST["password"])):
  //Enter the new user in the database
    $sql = "INSERT INTO users (email, password) VALUES (:email, :password)";
    $stmt = $conn->prepare($sql);
    $stmt->bindParam(":email", $_POST['email']);
    $stmt->bindParam(":password", password_hash($_POST['password'], PASSWORD_BCRYPT));
    if ($stmt->execute() ):
      $message = 'Successfully created a new user';
    else:
      $message = 'Sorry there must have been an issue whilst registering';
    endif;
  endif;
?>

这是表格:

<div class="jumbotron" id="jumbotron-6">
  <div class="container text-center">
  <?php if (!empty($message)):
  ?>
  <h3 id="h3message"><?= $message ?> </h3>
<?php endif; ?>
     <form action="signup.php" method="POST">
      <input type="text" placeholder="enter your email" name="email"> 
        <input type="password" placeholder="and password" name="password">
          <input type="password" placeholder="confirm password" name="confirm_password">
        <input type="submit">
    </form> 
  </div>
</div>

它不会插入到数据库中(我认为所有字段、变量都是正确的 - 只是电子邮件和密码),并且它返回我创建的错误消息,上面写着"抱歉,注册时一定有问题"

这是数据库.php文件

<?php 
$server =  'localhost';
$username = "root";
$password = "";
$database = "auth";
try{
  $conn = new PDO ("mysql:host={$server};dbname={$database};" , $username, $password);
} 
catch (PDOException $e) {
  die ( "Connection failed; " . $e->getMessage());
} 
?>

在绑定密码之前对其进行哈希处理:

$UserPWHash = password_hash($_POST['password'], PASSWORD_BCRYPT);
$stmt->bindParam(":password", $UserPWHash));