Neden bu sql deyimi bir mantıksal ve bir parametre olduğunu söylüyor?

4 Cevap php

Bu bildiride, ben tam olarak aynı başlık, fiyat, şehir, eyalet, detay vardır veritabanında son gönderme olup olmadığını görmek için çalışıyorum. Varsa, o zaman kesin sonrası zaten yapılmış kullanıcıya söyleyebilirim; sonra DBC içine ilanı eklemek değilse. (:) Kullanıcıların yanlışlıkla Bu iyi kontrol olmayabilir. Kez açamazsınız böylece bu çek bir türüdür, ancak bu açıklama hata beni rahatsız olduğunu, bu yüzden çalışmak istiyorum)

Neden bu sql çalışmaz? Ben title=$title izin vermiyor ve $title değerini elde değil düşünüyorum ...

> 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 Cevap

Vay ben geri temel Mysql kurallarına gitmek gerekir sanırım ...

$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'
";

Bu 'hataya neden neydi

mysqli_query($dbc, $query) Eğer $data atama ve geçen olan mysqli_num_rows, FALSE dönüyor

this page bunu return false neden olabilir ne görmek için bkz.

Böyle num satırlar durumunu deneyin

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

Manuel (mysqli_query ()):

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query()  will return a result object. For other successful queries mysqli_query()  will return TRUE. 

Yani sorguda hata var.