dourang6858 2016-06-15 20:22
浏览 61
已采纳

PHP在非对象上调用成员函数bind_param()[duplicate]

This question already has an answer here:

So I'm having the same problem for 3 hours straight and I've been searching Stack Overflow, Google and even Bing (yes even Bing..) for the right answer but I can't seem to find a solution...

The problem:

I try to insert data into my database using a prepared statement, but I keep getting the same error over and over again. I'm using everything in the right order and stuff so that's not the mistake...

My code:

//INCLUDES FILES THAT HOLD ALL DATA (servername, username, ...)

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

 // prepare and bind
 $stmt = $conn->prepare("INSERT INTO REGISTRY (user_ref, email_user, date_created, title, tweet, description, category, filename, invoice) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
 $stmt->bind_param("sssssssss", $gebruikerID, $email, $date_created, $title, $tweet, $description, $category, $nameImage, $customUniqueId);

// set parameters and execute
$gebruikerID = $gebruikerID;
$email = $email;
$date_created = date("d/m/Y H:i:s");
$title = date("d/m/Y H:i:s");
$tweet = $_POST["tweet"];
$description = $_POST["project_description"];
$category = $_POST["category"];
$nameImage = $nameImage;
$customUniqueId = $_GET["redirect"];

$stmt->execute();

echo "New records created successfully";

$stmt->close();
$conn->close();

The error I'm getting for 3 hours straight:

Fatal error: Call to a member function bind_param() on a non-object on line 148

</div>
  • 写回答

1条回答 默认 最新

  • douzi2785 2016-06-15 20:52
    关注

    For those of you that have the same problem like me, here's what was wrong:

    I had forgotten to put every row of my database in the code... So what I ended up was go to phpmyadmin and go to the table i wanted to insert some data in. Then I clicked SQL and I chose insert.

    After that, I got a code and I replaced all [val-x] with ? And ended up with this code:

    // prepare and bind
    $stmt = $conn->prepare("INSERT INTO `projecten`(`user_ref`, `email_user`, `date_created`, `title`, `tweet`, `description`, `category`, `filename`, `invoice`, `admin_checkup`, `visible`, `project_finished`, `deleted`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
    
    $stmt->bind_param("sssssssssssss", $gebruikerID, $email, $date_created, $title, $tweet, $description, $category, $nameImage, $customUniqueId, $adminCheck, $visible, $project_finished, $deleted);
    
    // set parameters and execute
    $gebruikerID = $gebruikerID;
    $email = $email;
    $date_created = date("d/m/Y H:i:s");
    $title = date("d/m/Y H:i:s");
    $tweet = $_POST["tweet"];
    $description = $_POST["project_description"];
    $category = $_POST["category"];
    $nameImage = $nameImage;
    $customUniqueId = $_GET["redirect"];
    $adminCheck = "0";
    $visible = "0";
    $project_finished = "0";
    $deleted = "0";
    
    $stmt->execute();
    

    I hope this helps you guys out!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题