PHP and MySQLi - Cannot Pass Parameter 2 by Reference In

PHP/Mysqli insert : Cannot pass parameter 2 by reference

Your issue are the single quoted variables. Just remove the single quotes or use double quotes for the content of double quotes is partitial evaluated / parsed:

$a=3;
echo '$a'; // prints: $a
echo "$a"; // prints: 3
echo $a; // prints: 3 and this is just what you need

You do not need the quotes for variables, so just remove them:

$stmt->bind_param("sis", $username, $session, $contactinfo);

Cannot pass parameter by reference in MySQLi

'1' cannot be passed by reference because it's not a variable but a literal. You need to create a variable with mentioned value and bind it instead because bind_param() function expects variables passed by reference.

PHP error: Cannot pass parameter 2 by reference

The error means that the 2nd argument is expected to be a reference to a variable.

Since you are not handing a variable but an integer of value 0, it generates said error.

To circumvent this do:

$a = 0;
$update->bind_param("is", $a, $selectedDate); //LINE 13

In case you want to understand what is happening, as opposed to just fixing your Fatal error, read this: http://php.net/manual/en/language.references.pass.php

Cannot pass parameter by reference - MySQLi

You can't use 'Open' in your bind_param call. bind_param requires that each parameter is a reference.

You need to store that in a variable first.

$status = 'Open';
$stmt->bind_param('sssssss', $_POST['post_subject'], $_POST['post_description'], $_POST['post_assigned'], $status, $userid, $_POST['post_priority'], $_POST['post_employee']);

Prepared Statement Cannot pass parameter 2 by reference.

$stmt->bind_param("ii", 1, $id);
---^

It's because 1 is not a parameter, it's an integer. You'll need to use bindValue instead.

Fatal error: Uncaught Error: Cannot pass parameter 2 by reference

You have 2 placeholders in your query so you need to bind two variables.

//                       V        and      V
WHERE `user_deped_email`=? OR `user_email`=?

bind_param() should be:

$stmt->bind_param('ss', $depedemail, $personalemail);

$depedemail OR $personalemail is an expression, and an expression is not a variable. You can't pass the result of an expression by reference.

Cannot pass parameter by reference

The problem is here, because bind_param() requires all its arguments be passed by reference (except the first arg which is the control string).

$stmt->bind_param("ssssssssssssssss", '1', $adminEmail, $adminPass, $adminUsername, 
'', '', '', '', '1', '1', 'english',);

String literals like '1' are not lvalues, so they cannot be passed by reference.

You can fix it this way:

$one = '1';
$blank = '';
$english = 'english';

$stmt->bind_param("ssssssssssssssss", $one, $adminEmail, $adminPass, $adminUsername,
$blank, $blank, $blank, $blank, $one, $one, $english);

If it were me, I'd use PDO instead of mysqli. PDO has an easier method of passing parameters. No binding step necessary. Just pass as an array to execute(), and this accepts non-lvalues:

$stmt = $pdo->prepare(...);
$stmt->execute([
'1', $adminEmail, $adminPass, $adminUsername, '', '', '', '1', '1', 'english'
]);


Related Topics



Leave a reply



Submit