【问题标题】:Fatal error: Call to a member function bind_param() on a non-object致命错误:在非对象上调用成员函数 bind_param()
【发布时间】:2013-11-19 02:47:02
【问题描述】:

这是我的代码的一部分

$con = mysqli_connect("localhost","root","","baspdata",3306);
if (mysqli_connect_errno())
{ 
echo "Error connecting to database: ".mysqli_connect_error();
exit();
}
else
{ 
$result=mysqli_query($con,"SELECT * FROM member WHERE Username='$username' and Password = '$password'");
$row=$result->fetch_assoc();
$sellerId=$row['MemberId'];
$picturecontent= file_get_contents($productPic);    
$query ="INSERT INTO product (ProductName, ProductPicture, ProductDescription, ProductCategory, ProductPrice, UploadedDate, Sold, SellerId) VALUES(?,?,?,?,?,?,?.?)";
$stmt=$con->prepare($query);
$stmt->bind_param("ssssssss", $productName, $picturecontent, $description, $category, $price, $uploadedDate, $sold , $sellerId);
$stmt->execute();
$con->close();
echo "<h1>".$productName." added successfully! =)<br/> </h1>"; 

}

我收到错误 Fatal error: Call to a member function bind_param() on a non-object on the line $stmt->bind_param("ssssssss", $productName, $picturecontent, $description, $category, $price , $uploadedDate, $sold , $sellerId);但我无法弄清楚。请帮忙。

【问题讨论】:

  • Fatal error: Call to a member function bind_param() on a non-object 的意思正是它所说的。 $stmt 对象不是对象 - 当 prepare 调用失败并返回 false 而不是返回对象时会发生这种情况。
  • 如果您阅读prepare 的php 文档页面,您会看到它清楚地指出prepare 在失败时返回false。这意味着在将其用作对象之前,您始终需要检查返回的值是否为false

标签: php


【解决方案1】:

查询失败并且不返回准备好的语句外观,

VALUES(?,?,?,?,?,?,?.?)

改成

VALUES(?,?,?,?,?,?,?,?)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多