I have a block of code below which inserts data into database using mysqli and php. The problem is that I am getting a fatal error stating: Fatal error: Cannot pass parameter 2 by reference in … on line 116
Why is this error appearing and how can I fix the error?
Below is the code:
if ($numrows == 0){
$teacherpassword = md5(md5("j3Jf92".$teacherpassword."D203djS"));
$code = md5(rand());
$insertsql = "
INSERT INTO Teacher
(TeacherId, TeacherForename, TeacherSurname, TeacherEmail, TeacherAlias, TeacherUsername, TeacherPassword, Active, Code)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?)
";
if (!$insert = $mysqli->prepare($insertsql)) {
// Handle errors with prepare operation here
}
$insert->bind_param("sssssssss", '', $getfirstname, $getsurname,
$getemail, $getid, $getuser,
$teacherpassword, '0', $code);
$insert->execute();
if ($insert->errno) {
// Handle query error here
}
$insert->close();
mysqli_stmt::bind_param()takes one string detailing the types of the following arguments, and then a set of references to variables that contain the data.Only variables may be passed by reference, so you are not allowed to pass a string (
''or'0') to the function. You must put that string in a variable, and then pass that variable.If you’re passing constant values to an
INSERT, why not make them theDEFAULTvalues of those fields and then remove them from the query?