Reputation: 35
I'm trying to insert six records in a table, but when the script runs I get the following
error: 'Fatal error: Cannot pass parameter by reference'.
See the code below for the specific line:
$ySQL = "SELECT ID_USUARIO FROM USUARIOS WHERE EMAIL=?";
$stmt = $oConni->prepare($ySQL) or die($oConni->error);
$stmt->bind_param('s', $datos[8]);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($idUsuario);
$stmt->fetch();
$stmt->close();
for($i=1;$i<7;$i++){
$vSQL = "INSERT INTO PERMISOS (ID_USUARIO,ID_ACCION,PERMISOS) VALUES(?,?,?)";
$stmt = $oConni->prepare($vSQL) or die($oConni->error);
// ERROR. The following line throws it:
$stmt->bind_param('iis', $idUsuario, $i, 'S');
$stmt->execute();
$stmt->store_result();
$stmt->close();
}
Upvotes: 0
Views: 87
Reputation: 29424
Here is mysqli_stmt::bind_param()
's signature:
bool mysqli_stmt::bind_param ( string $types , mixed &$var1 [, mixed &$... ] )
As you can see, the method accepts all parameters – except the first one – as references.
You need at least a variable or a function's return value for having a reference. You cannot use a String Literal like 'S'
.
Here is a fix:
$str = 'S';
$stmt->bind_param('iis', $idUsuario, $i, $str);
Upvotes: 1