donglaogu3788 2010-04-17 18:40
浏览 125

为什么这个sql语句一直说它是布尔值而不是参数? (PHP / MySQL的)

In this statement, I am trying to see if there is the latest posting in the database that has exactly same title, price, city, state, detail. If there is, then it would say to the user that the exact post has been already made; if not then insert the posting into the dbc. (This is one type of check so that users can't accidentally post twice. This may not be the best check, but this statement error is annoying me, so I want it to work :))

Why won't this sql work? I think it's not letting the title=$title and not getting the value in the $title...

> ERROR: mysqli_num_rows() expects
> parameter 1 to be mysqli_result,
> boolean given in postad.php on line
> 365

    //there is a form that users fill out that has title, price, city, etc
    <form>
    blah blah
    </form>

         //if users click submit, then does all the checks and if all okay, insert to dbc
        if (isset($_POST['submit'])) 
        {

        // Grab the pposting data from the POST and gets rid of any funny stuff
        $title = mysqli_real_escape_string($dbc, trim($_POST['title']));
        $price = mysqli_real_escape_string($dbc, trim($_POST['price']));
        $city = mysqli_real_escape_string($dbc, trim($_POST['city']));
        $state = mysqli_real_escape_string($dbc, trim($_POST['state']));
        $detail = mysqli_real_escape_string($dbc, trim($_POST['detail']));

         if (!is_numeric($price) && !empty($price))
         {
            echo "<p class='error'>The price can only be numbers. 
                No special characters, etc</p>";
        }

        //Error problem...won't let me set title=$title, detail=$detail, etc.            
         //this statement after all the checks so that none of the variables are empty
        $query="Select * FROM posting 
    WHERE user_id={$_SESSION['user_id']}
    AND title=$title
    AND price=$price
    AND city=$city
    AND state=$state
    AND detail=$detail";
    $data = mysqli_query($dbc, $query);
    if(mysqli_num_rows($data)==1) 
    {
        echo "You already posted this ad. Most likely caused by refreshing too many times.";
    }

}
  • 写回答

4条回答 默认 最新

  • dpbz14739 2010-04-17 18:43
    关注

    Try num rows condition like this

    if(mysqli_num_rows($data)>0) {
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器