dsdvr06648 2016-07-18 09:20
浏览 67

函数bind_param()在布尔值上

I have this code, a simple retrieve mysql data, but I receive this error upon submit.

Fatal error: Call to a member function bind_param() on boolean

I know that there is alot of solution, but I can't seems to find where is the problem coming from

Here is my code:-

$mysqli = new mysqli("localhost", "poke", "password", "pokedb");

    if (isset($_POST['poke_name'])) {

    $query = "SELECT name,lat,long,pic,description FROM creature WHERE name LIKE ?";
    $param = "%{$_POST['poke_name']}%";

    $stmt = $mysqli->prepare($query);
    $stmt->bind_param("s", $param);
    $stmt->execute();
    $stmt->bind_result($name, $lat, $long, $pic, $description);

        /* fetch values */
        while ($pokeinfo = $stmt->fetch_assoc()) {
            $poke_info[] = $pokeinfo;
        }

        /* close statement */
       $mysqli->close();

    }
  • 写回答

2条回答 默认 最新

  • douben7260 2016-07-18 09:26
    关注

    The prepare has failed. Test the status returned by the prepare and then echo $mysqli->error

    $mysqli = new mysqli("localhost", "poke", "password", "pokedb");
    /* check connection */
    if ($mysqli->connect_errno) {
        printf("Connect failed: %s
    ", $mysqli->connect_error);
        exit();
    }
    
    if (isset($_POST['poke_name'])) {
    
        $query = "SELECT name,lat,long,pic,description FROM creature WHERE name LIKE ?";
        $param = "%{$_POST['poke_name']}%";
    
    
        $stmt = $mysqli->prepare($query);
        if ( $stmt === false ) {
            echo $mysqli->error;
            exit;
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据