Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取错误严格标准:第20行register.php中的引用只能传递变量_Php_Database_Login - Fatal编程技术网

获取错误严格标准:第20行register.php中的引用只能传递变量

获取错误严格标准:第20行register.php中的引用只能传递变量,php,database,login,Php,Database,Login,我从GitHub()下载了登录php脚本,当我尝试注册时,它会显示以下错误:Strict Standards:只有变量应该在第20行的/bookmook/register.php中通过引用传递 在登录页面上,它不会显示任何错误 我使用的代码: <?php session_start(); if( isset($_SESSION['user_id']) ){ header("Location: /"); } require 'datab

我从GitHub()下载了登录php脚本,当我尝试注册时,它会显示以下错误:
Strict Standards:只有变量应该在第20行的/bookmook/register.php中通过引用传递
在登录页面上,它不会显示任何错误

我使用的代码:

 <?php

    session_start();

    if( isset($_SESSION['user_id']) ){
        header("Location: /");
    }

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

    endif;

    ?>

    <!DOCTYPE html>
    <html>
    <head>
        <title>Register Below</title>
        <link rel="stylesheet" type="text/css" href="assets/css/style.css">
        <link href='http://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet' type='text/css'>
    </head>
    <body>

        <div class="header">
            <a href="/">Homework</a>
        </div>

        <?php if(!empty($message)): ?>
            <p><?= $message ?></p>
        <?php endif; ?>

        <h1>Register</h1>
        <span>or <a href="login.php">login here</a></span>

        <form action="register.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>

    </body>
    </html>

在下面注册

登记 或
database.php(如果需要):


将值传递给
bind_param()
时,需要传递变量,而不是函数的返回值

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

当您看到一个参数前面有一个
&
,如中的
&$variable

公共bool语句::bindParam(混合$parameter,混合 &$variable[,int$data_type=PDO::PARAM_STR[,int$length[,mixed $driver\u选项]]])

您需要传递一个变量

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