Why does this sql statement keep saying it is a boolean and not a paramter? (php/Mysql)

Posted by ggfan on Stack Overflow See other posts from Stack Overflow or by ggfan
Published on 2010-04-17T18:40:00Z Indexed on 2010/04/17 18:43 UTC
Read the original article Hit count: 188

Filed under:
|

In this statement, I am trying to see if there if the latest posting in the database that has the exact 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.";
}

}

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql