Cannot pass parameter 2 by reference error in php PDO

前端 未结 2 1980
广开言路
广开言路 2021-01-15 03:51

I am getting the error: Cannot pass parameter 2 by reference in.....

in this line...

$stmt1->bindParam(\':value\', $_SESSION[\'quantity\'.$i] * $_         


        
2条回答
  •  孤城傲影
    2021-01-15 04:20

    It expects the second paramter to be a variable which can be passed by reference. Assuming $stmt1is a PDO statement then, as the docs for bindparam say

    Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called.

    Your second param is an expression ($_SESSION['quantity'.$i] * $_SESSION['price'.$i]) not a variable. Since you appear to want to evaluate the exptression now, I guess you should used bindValue() instead.

提交回复
热议问题