Error Only variables should be passed by reference when Inserting data by query parameterized with PHP and MySQL

0

I have the following code:

    public function nuevoUsuario($id_empleado, $username, $correo, $pass, $id_tipo_usuario) {
    //tiempo de espera
    sleep(1);
    try {

        $this->Conectar_BD();
        $this->query = "INSERT INTO usuarios(id_empleado, correo, pass, id_tipo_usuario, username) VALUES (?,?,?,?,?)";
        $this->consulta = $this->conexion_bd->prepare($this->query);
        $this->consulta->bind_param('sssis',$id_empleado,$correo, md5($pass),$id_tipo_usuario,$username);

        if ($this->consulta->execute()) {
            //Si se hace correctamente imprimimos true
            echo "true";
        } else {
            //Sino imprimimos false
            echo "false";
        }
    } catch (Exception $e) {
        echo "false";
    }
}

Which at the time of being executed sends me the following message:

  


Notice : Only variables should be passed by reference in C: \ xampp \ htdocs \ SICC-GC29012018 \ 29012018 \ SICC - GC \ php \ classes.php on line 152
  false

I really do not know what to do, previously it worked for me.

  

Line 152 :

$this->consulta->bind_param('sssis',$id_empleado,$correo,md5($pass),$id_tipo_usuario,$username);
    
asked by Ferny Cortez 02.02.2018 в 21:56
source

1 answer

2

I think you have the error when wanting to pass md5 ($ pass) as a reference.

It would be best to save that value in a variable before passing it to bind_param .

Example:

$password = md5($pass); 

$this->consulta->bind_param('sssis',$id_empleado,$correo,$password,$id_tipo_usuario,$username);

MD5

  

It is not recommended to use this function for secure passwords due   to the fast nature of this hashing algorithm.

link

Recommended to save passwords:

link

PHP and MYSQL password storage

    
answered by 02.02.2018 / 22:30
source