Home > Backend Development > PHP Tutorial > Why Does My PHP Code Throw a 'Cannot pass parameter 2 by reference' Error in `mysqli::bind_param()`?

Why Does My PHP Code Throw a 'Cannot pass parameter 2 by reference' Error in `mysqli::bind_param()`?

Linda Hamilton
Release: 2024-12-08 07:15:15
Original
159 people have browsed it

Why Does My PHP Code Throw a

"Cannot pass parameter 2 by reference" PHP Error

When encountering this error, it indicates that the function or method in question expects the second parameter to be passed by reference, yet a value is being passed instead.

In this specific case, the error arises from the bind_param method within the mysqli class. This method expects the second parameter to be a reference to a variable, but the code attempts to pass it an integer value of 0.

To rectify this error, a new variable should be created (such as $a) and assigned the value of 0. Then, the bind_param method can be called with $a as the second parameter:

$a = 0;
$update->bind_param("is", $a, $selectedDate);  // Line 13 corrected
Copy after login

This approach ensures that the bind_param method receives a reference to a variable, as required.

The above is the detailed content of Why Does My PHP Code Throw a 'Cannot pass parameter 2 by reference' Error in `mysqli::bind_param()`?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template