gpt4 book ai didi

php - 在我的新代码中对非对象执行 bind_param() 函数

转载 作者:行者123 更新时间:2023-11-29 06:20:20 25 4
gpt4 key购买 nike

我正在尝试将我的 PHP 代码更改为另一个安全代码,因此我更改了 update.PHP 页面 from this对此:

<?php 
require_once ('../include/global.php');
$id=$_REQUEST['id'];

if (isset ($_POST['name'])) {
$name = $_POST['name'];
}
if (isset ($_POST['remarcs'])) {
$remarcs = $_POST['remarcs'];
}
if (isset ($_POST['test_res'])) {
$test_res = $_POST['test_res'];
}
if (isset ($_POST['address'])) {
$address = $_POST['address'];
}

if (isset ($_POST['date'])) {
$date = $_POST['date'];
}

if (isset ($_POST['phone_num'])) {
$phone = $_POST['phone_num'];
}

if (isset ($_POST['illness'])) {
$illness = $_POST['illness'];
}
if (isset ($_POST['echo'])) {
$echo = $_POST['echo'];
}
if (isset ($_POST['pe'])) {
$pe = $_POST['pe'];
}
if (isset ($_POST['pmhx'])) {
$pmhx = $_POST['pmhx'];
}
if (isset ($_POST['pshx'])) {
$pshx = $_POST['pshx'];
}
if (isset ($_POST['habbits'])) {
$habbits = $_POST['habbits'];
}
if (isset ($_POST['occup'])) {
$occup = $_POST['occup'];
}
if (isset ($_POST['allergy'])) {
$allergy = $_POST['allergy'];
}

//Check file is uploaded or not
//if (isset($_FILES['file']['name']) && $_FILES['file']['name']!='' && $_FILES['file']['error']=='') {
//$path2 = ... ;
//move_uploaded_file(...);
if(is_uploaded_file($_FILES["file"]["tmp_name"]))
{
$path = "../uploads/".$_FILES['file']['name'];
move_uploaded_file($_FILES["file"]["tmp_name"], $path);
$new_path = "./uploads/".$path;

}
else{
$new_path = $_POST['org_path'];
//$path2 = "../uploads/".$_FILES['echo_photo']['name'];
}
$sql=('UPDATE $tbl_name SET name = ?,
echo_files = ?,
remarcs = ?,
test_res = ?,
date = ?,
address = ?,
phone_num = ?,
illness = ?,
echo = ?,
pmhx = ?,
pshx = ?,
habbits = ?,
occup = ?,
allergy = ?,
pe = ?
WHERE id = ? ');
$stmt= $con->prepare($sql);
$stmt->bind_param("ssssssssssssssi", $name, $path, $remarcs, $test_res, $date, $address, $phone,
$illness, $echo, $pmhx, $pshx, $habbits, $occup, $allergy, $pe, $id);
$stmt->execute();

if($stmt->errno){
echo "FAILURE!!! " . $stmt->error;
}
else {
header("location:update_done.php");
}
?>

现在我收到这个错误:

Fatal error: Call to a member function bind_param() on a non-object in So any help with this ?

最佳答案

prepare() 方法在出现错误时返回 false here .您应该将其保存在 if 语句中。

您的查询字符串不会解释变量 $tbl_name,因为您使用的是单引号。它可以用 '.$tbl_name.' 修复。

关于php - 在我的新代码中对非对象执行 bind_param() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33561547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com