Only variables should be passed by reference in… on line 13 Fail

前端 未结 2 1415
陌清茗
陌清茗 2020-12-12 03:48

I\'m practicing building a PHP registration form script for a website. I have done this code, but when I click the submit button I get the notice: Only variables should be p

相关标签:
2条回答
  • 2020-12-12 04:24

    change this

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

    to this

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

    the error message is clear though you need to assign those values into variables then pass them

    0 讨论(0)
  • 2020-12-12 04:40

    $result->bindParam(':id', $id, PDO::PARAM_INT);

    if string, you need write:
    $stmt->bindParam(':username', $_POST['username'], PDO::PARAM_STR);

    0 讨论(0)
提交回复
热议问题