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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?