解析错误:语法错误,php代码文件的意外结束


Parse error: syntax error, unexpected end of file for php code

每当我尝试查看该站点时,我都会收到错误消息。下面是代码:

<?php
 $server = '127.0.0.1';
 $username = 'root';
 $db_name = 'auth';
try{
  $conn = new PDO("mysql:host=$server;dbname=$database;", $username);}
  catch(PDOException $e){
  die( "Connection failed: " . $e->getMessage());
   }
if(!empty($_POST['email']) && !empty($_POST['password'])):
  // enter the new user in the database
  $sql = "INSERT INTO users (email, passowrd) VALUES (;email, :password);
  $stmt = $conn->prepare($sql);
  $stmt->bindParam':email'],_POST['email'];
  $stmt->bindParam((':password',password_hash(POST['password'], PASSWORD_BCRYPT));
  if( $stmt->execute() ):
   die('Success');
  endif;
 endif;
   ?>

我不明白为什么它说php代码的结束括号是意外的。

你的脚本中有很多语法错误。

  • 查询字符串;email中应该是:email。另外,右引号缺少

    $sql = "INSERT INTO users (email, passowrd) VALUES (:email, :password)";

                                                      ^^^^               ^^^
    
  • bindParam缺少括号。POST之前缺少$_

    $stmt->bindParam(':email', $_POST['email']);

                   ^^^                      ^^^^
    
  • ($_POST不匹配的问题下面的语句:

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

希望您能明白。