在我的新代码中的非对象上使用函数 bind_param() [英] function bind_param() on a non-object in my new code
本文介绍了在我的新代码中的非对象上使用函数 bind_param()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将我的 PHP 代码更改为另一个安全的代码,因此我更改了 update.PHP 页面 从这个到那个:
I am trying to change my PHP code into another secure one so I change the update.PHP page from this to that:
<?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");
}
?>
现在我收到此错误:
致命错误:在非对象上调用成员函数 bind_param()那么这有什么帮助吗?
Fatal error: Call to a member function bind_param() on a non-object in So any help with this ?
推荐答案
因为你没有在你的代码中定义 $tbl_name
Because You are not define $tbl_name
in your code
$sql=('UPDATE $tbl_name SET name = ?,.....
它会产生
UPDATE SET name = ?...
尝试设置您的表名
这篇关于在我的新代码中的非对象上使用函数 bind_param()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文