drtppp75155 2014-01-29 21:57
浏览 187
已采纳

bind_param()问题

I am getting issues with the bind_param function. I will post all the information below.

Error:

Fatal error: Call to a member function bind_param() on a non-object in /home4/lunar/public_html/casino/blogpost.php on line 88

MySQL Error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':user, :title, :message, :image, :category, NOW())' at line 1

Query:

    $user = $_COOKIE['user'];
    $title = $_POST['title'];
    $message = $_POST['message'];
    $image = $_POST['image'];
    $category = $_POST['category'];
    $stmt = $mysqli->prepare("INSERT INTO `lunar_casino`.`posts` (`id`, `by`, `title`, `message`, `image`, `category`, `date`) VALUES(NULL, :user, :title, :message, :image, :category, NOW())");
    echo $mysqli->error;
    $stmt->bind_param(":user", $user);
    $stmt->bind_param(":title", $title);
    $stmt->bind_param(":message", $message);
    $stmt->bind_param(":image", $image);
    $stmt->bind_param(":category", $category);
    $stmt->execute();
    if(!$stmt){
      echo "<font color='red'><b>There has been an error with our database! Please contact the website administrator!</b></font><br /><br />";
      echo $mysqli->error;
    } else {
      echo "<font color='green'><b>You have successfully added a blog post!</b></font><br /><br />";
    }

Any ideas why its like this?

  • 写回答

2条回答 默认 最新

  • dongtang4954 2014-01-29 22:03
    关注

    As Rocket Hazmat mentioned you can only use question marks as bind parameter place holder. You should do something similar:

     $stmt = $mysqli->prepare("INSERT INTO `lunar_casino`.`posts` (`id`, `by`, `title`, `message`, `image`, `category`, `date`) VALUES(NULL, ?, ?, ?, ?, ?, NOW())");
     $stmt->bind_param("sssss", $user, $title, $message, $image, $category);
    

    More details: http://www.php.net/manual/en/mysqli-stmt.bind-param.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧