Call to a member function bind_param() on a non-object. mysqli [duplicate]

╄→尐↘猪︶ㄣ 提交于 2020-01-03 06:41:28

问题


This is my php code:

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();
}

This is my form:

    <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:

Fatal error: Call to a member function bind_param() on a non-object in /storage/content/x/xxx/ on line 27.

Line 27 is:

$stmt->bind_param('ssd',

I'm not familiar with mysqli. I have tried to fix the problem for a few days now and I'm getting crazy.


回答1:


This means that the query inside mysqli::prepare() resulted in an error.

According to the doc:

mysqli_prepare() returns a statement object or FALSE if an error occurred.

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 = ?');


来源:https://stackoverflow.com/questions/18931384/call-to-a-member-function-bind-param-on-a-non-object-mysqli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!