将我的代码更改为mysqli过程中的准备语句,其中它在提交到我的php文件后显示此错误。
致命错误:无法通过引用传递参数8
这是我的php代码。
我刚刚将这段代码从插入数据复制到不带数组的db中,但是这个php代码会得到数组。
<?php
include 'admin/db/database_configuration.php';
if(isset($_POST['submit'])){
if (empty($_POST['title'])){$job_title = 'NULL'; } else{ $job_title ="'". mysqli_real_escape_string($conn, $_POST['title']) . "'";}
if (empty($_POST['desc'])){$job_desc = 'NULL'; } else{ $job_desc ="'". mysqli_real_escape_string($conn, $_POST['desc']) . "'";}
$qualifications ="";
if(isset($_POST["quali"]) && is_array($_POST["quali"])){
$qualifications = implode("\n", $_POST["quali"]);
}
if (empty($_POST['name_cont'])){$name_contact = 'NULL'; } else{ $name_contact ="'". mysqli_real_escape_string($conn, $_POST['name_cont']) . "'";}
if (empty($_POST['contact'])){$contact_num = 'NULL'; } else{ $contact_num ="'". mysqli_real_escape_string($conn, $_POST['contact']) . "'";}
if (empty($_POST['email_add'])){$email_cont = 'NULL'; } else{ $email_cont ="'". mysqli_real_escape_string($conn, $_POST['email_add']) . "'";}
$stmt = $conn->prepare("INSERT INTO `tbljoba` (job_title, job_desc, job_qualifications, cont_name, contact_info, employer_email, job_status) VALUES(?,?,?,?,?,?,?)") or die(mysqli_error($conn));
$stmt->bind_param("sssssss", $job_title, $job_desc, $qualifications, $name_contact, $contact_num, $email_cont, 'pending'); //bind to param
if($stmt->execute()){
$stmt->close();
$conn->close();
echo '<script>alert("Successfully Sent")</script>';
echo '<script>window.location = "employer_contact_us.php"</script>';
}else{
echo '<script>alert("Error")</script>';
}
}
$conn->close();
?>
在这一行中,我有一个错误
$stmt->bind_param("sssssss", $job_title, $job_desc, $qualifications, $name_contact, $contact_num, $email_cont, 'pending'); //bind to param
发布于 2017-03-04 10:21:04
错误发生在'pending'
调用的bind_param
中。
所有参数都必须通过引用传递给bind_param
。字符串是一个基本值,不能通过引用传递。
您可以通过创建变量并将其作为参数传递来修复此问题:
$status = 'pending';
$stmt->bind_param("sssssss", $job_title, $job_desc, $qualifications, $name_contact, $contact_num, $email_cont, $status); //bind to param
或者,如果状态总是挂起,则可以将其硬编码到查询中。
// add 'pending' into the VALUES part of the query
$stmt = $conn->prepare("INSERT INTO `tbljoba` (job_title, job_desc, job_qualifications, cont_name, contact_info, employer_email, status) VALUES(?, ?, ?, ?, ?, 'pending')") or die(mysqli_error($conn));
// no need to bind 'pending'
$stmt->bind_param("ssssss", $job_title, $job_desc, $qualifications, $name_contact, $contact_num, $email_cont); //bind to param
https://stackoverflow.com/questions/42594734
复制相似问题