2016-04-08 87 views
0

我正在按照创建注册和登录系统的教程。我尽一切努力,但当我按下提交表单时,仍然出现奇怪的严格标准错误。严格的标准错误,同时保存注册数据

<?php 

require 'pdoconnect.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 new user'; 
else: 
    $message = 'Sorry there must have been an issue creating your account'; 
endif; 

endif; 

?> 

它说

严格的标准:只有变量应该通过线14(与密码哈希线)引用传递。

我已经找遍了解决方案,但我无法找到任何。

+0

在使用'bindParam()'中的散列值之前,您应该对密码*进行散列* –

回答

1

散列你将它绑定之前的密码

// Enter the new user in the database 
$sql = "INSERT INTO users (email, password) VALUES (:email, :password)"; 
$stmt = $conn->prepare($sql); 

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

你不能传递一个函数到绑定参数,你只能传递一个变量。

+1

谢谢!密码现在已经在数据库中安全散列:) – SmashingJummy

+1

很好......看看你先生的花式裤。现在我们将不得不打电话给你先生“热”裤萨姆。 –

+1

*我gotcho'热裤权hea'拉尔夫!* @ Fred-ii- –