Fatal error: Cannot pass parameter 2 by reference in line 68

I am getting this error kindly help…

register.php

  ini_set('display_errors', '1');
  ini_set('display_startup_errors', '1');
  error_reporting(E_ALL);

  include_once 'includes/config.php'; 

 

  
if ($_SERVER['REQUEST_METHOD'] == 'POST') { 

  //collect form data and store in variables
  
  $username = trim($_POST['username'] );
  $email = trim($_POST['email'] );
  $password = md5($_POST['password']);
 

 

    //validation from user

    if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
    
        $error = "Enter a  valid email";

    }elseif (strlen($username) <= 4) {

      $error = "Username is too Short";

    }elseif (strlen($_POST['password']) <= 6) {

              $error = "Password too short";
      }else{

              $sql = $dbh -> prepare ("SELECT * FROM users WHERE email=?");

              $sql->execute([$email]);

              $result = $sql->fetch();

              if($result){
                    
                     $error="The email is already taken";

              }else{

              $sql = $dbh -> prepare ("SELECT * FROM users WHERE username=?");

              $sql->execute([$username]);

              $result = $sql->fetch();

              if($result){
                    
                     $error="The username is already taken";


              }else{

                 $sql = "INSERT INTO users (username, email, password, rights )values( :username, :email, :password :rights )";
                  $query = $dbh -> prepare($sql);
                  //Bind the parameters
                  $query->bindParam(':email', $email,PDO::PARAM_STR);
                  $query->bindParam(':username', $username,PDO::PARAM_STR);
                  $query->bindParam(':password', $password,PDO::PARAM_STR);
                  $query->bindParam(':rights', 'User'); //Line 68
                  $query->execute();
                  
                  header('Location: login.php');

                  exit(); 
                }

                  }
             } 

        }
 
?>

dddd

Try that maybe.

$sRights = 'User';
$query->bindParam(':rights', $sRights); //Line 68

bindParam expects a variable, not a string. If you want to bind a string you need bindValue

Also, do not store password plaintext in the database, use password_hash to store them securely!

Thanks

Thanks. Its just a demo that’s why I didnt hash it but I will take note of that.

Nothing was inserted in the Database after the changes i made.??

There is comma missing between :password and :rights

( :username, :email, :password :rights )
                              ^-- there should be a comma here
2 Likes

Thanks so much..It worked.:smile: I guess I wasn’t keen enough, thanks again.

The database would have reported that if PDO’s error reporting were enabled.

… what can be acomplished by

$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)

on non-productive systems.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.