2016-08-25 113 views
-3

每當我嘗試查看網站時,都會收到錯誤消息。這裏是代碼:解析錯誤:語法錯誤,PHP代碼的文件意外結束

<?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代碼的結束括號是意想不到的。

+2

無處不在的語法錯誤。 ';'而不是';'在'; email'上。缺少'$ _'s,缺少用於結束字符串的結束引號。缺少括號。 –

回答

0

腳本中有很多語法錯誤。

  • 在查詢字符串;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));

希望這將是清楚的給你。

相關問題