调用非对象上的成员函数bind_param(). mysqli [英] Call to a member function bind_param() on a non-object. mysqli
本文介绍了调用非对象上的成员函数bind_param(). mysqli的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的php代码:
include ("dbinfo.php");
if(isset($_POST['editsave'])){
$edittitle=$_POST["edittitle"];
$editurl=$_POST["editurl"];
$editdesc=$_POST["editdesc"];
$editid=$_POST["editid"];
$mysqli = $GLOBALS['dbc'];
$stmt = $mysqli->prepare("UPDATE links SET title = ?,
\desc = ?
WHERE id = ?");
$stmt->bind_param('ssd',
$_POST['edittitle'],
$_POST['editdesc'],
$_POST['editid']);
$stmt->execute();
$stmt->close();
}
这是我的表格:
<form role="form" action="edit.php" method="post">
<div class="form-group">
<label for="title">Title</label>
<input type="text" name="edittitle" class="form-control" id="title" placeholder="Enter title" maxlength="70" value="<?php echo ($title); ?>">
</div>
<div class="form-group">
<label for="url">URL</label>
<input type="text" name="editurl" class="form-control" id="url" value="<?php echo ($url); ?>" disabled>
</div>
<div class="form-group">
<label for="desc">Description</label><small> (max 500 characters)</small>
<textarea class="form-control" name="editdesc" id="desc" rows="5" maxlength="500"><?php echo ($desc); ?></textarea>
</div>
<div>
<input type="hidden" name="editid" value="<? echo $id; ?>">
<button type="submit" name="editsave" class="btn btn-primary">Save changes</button>
</div>
</form>
当我按下提交时,我得到这个:
When i press submit i get this:
致命错误:在第27行的/storage/content/x/xxx/中的非对象上调用成员函数bind_param().
Fatal error: Call to a member function bind_param() on a non-object in /storage/content/x/xxx/ on line 27.
第27行是:
$stmt->bind_param('ssd',
我不熟悉mysqli.我已经尝试解决了几天问题,而且我也快疯了.
I'm not familiar with mysqli. I have tried to fix the problem for a few days now and I'm getting crazy.
推荐答案
这意味着根据文档:
mysqli_prepare()返回一个语句对象,如果发生错误则返回FALSE.
mysqli_prepare() returns a statement object or FALSE if an error occurred.
尝试正确地转义desc
,这是MySQL中的保留关键字(\
不能正确转义):
Try to properly escape desc
, which is a reserved keyword in MySQL (\
is not proper escaping):
$stmt = $mysqli->prepare('UPDATE links SET title = ?, `desc` = ? WHERE id = ?');
这篇关于调用非对象上的成员函数bind_param(). mysqli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文