每当我尝试查看该网站时,都会收到错误消息。这是代码:
<?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代码的结束括号是意料之外的。
答案 0 :(得分: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));
希望你能清楚。