When i try to Register on my website this error appears Strict standards: Only variables should be passed by reference. Can you see what is wrong with my code?
public static function create(user $user){
$conn= DataBase::getDB();
$stmt=$conn->prepare("INSERT INTO `institute`.`user` (`id`, `name`, `surname`, `username`, `password`, `email`, `registration_number`) "
. "VALUES ('', :name, :surname, :username, :password, :email, :registration_number)");
$stmt->bindParam(':name', $user->getName());
$stmt->bindParam(':surname', $user->getSurname());
$stmt->bindParam(':username', $user->getUsername());
$stmt->bindParam(':password', $user->getpassword());
$stmt->bindParam(':email', $user->getEmail());
$stmt->bindParam(':registration_number', $user->getRegistration_number());
$stmt->execute();
}
1
https://www.php.net/manual/en/pdostatement.bindparam.php
public bool PDOStatement::bindParam ( mixed $parameter , mixed &$variable [, int $data_type = PDO::PARAM_STR [, int $length [, mixed $driver_options ]]] )
Notice the second variable is of type mixed and is passed by reference.
In your case, you are trying to pass a function into that variable. Functions cannot be passed by reference.
You will need to change your code to either treat those as class properties or you’ll need to set them as variables before passing them to bindParam.
IE:
$userName = $user->getName();
$stmt->bindParam(':name', $userName);
You can, also, use bindValue:
https://www.php.net/manual/en/pdostatement.bindvalue.php
1
bindParam()
$username = $user->getName();
$stmt->bindParam(':name', $username);
bindValue()
$stmt->bindValue(':name', $user->getName());