PHP警告 - mysql_num_rows()期望参数1是资源

时间:2014-07-07 02:51:12

标签: php mysql

我正在尝试在我工作的公司网站上注册某些内容时收到此PHP警告。我没有写这个代码,所以我不太清楚发生了什么,但这是我得到的错误 - 警告:mysql_num_rows()期望参数1是资源,在/home/mojo/public_html/warranty/warranty_reg_get_my_stock.php中给出的布尔值第16行

这是代码

<?php
include('conf.php');

$dealer_id = $_SESSION['dealer_id'];
$start_vin = $_GET['vin'];

$query = "SELECT customer_id FROM dealers_myob WHERE dealer_id = ".$dealer_id;
$result = mysql_query($query);
$array = mysql_fetch_array($result);

$customer_id = $array['customer_id'];

$query = "SELECT vin FROM mojo_myob.vins WHERE customer = ".$customer_id." AND registered = 0 AND vin LIKE '".$start_vin."%' ORDER BY vin ASC"; 
$result = mysql_query($query);

if(mysql_num_rows($result)) {
    $vins = '<select id="my_stock_select" size="7"  onclick="copyVIN(this.value);" onchange="copyVIN(this.value);">';

    while($array = mysql_fetch_array($result)) {
        //check to see if registered, if not, show entry
        $current_vin = str_replace(" ", "", $array['vin']);
        $current_vin = str_replace("-", "", $current_vin);
        $reg_query = "SELECT * FROM warranty_registration WHERE frame_num LIKE '".$current_vin."'";
        $reg_result = mysql_query($reg_query);
        $reg_count = mysql_num_rows($reg_result);

        if(!$reg_count) {
            //does not exist, so show the entry
            $vins .= '  <option value="'.$current_vin.'">'.$current_vin.'</option>';
        }
    }
    $vins .= '</select>';

    echo $vins;
} else {

        $vins = '<select id="my_stock_select" size="7">';
        $vins .= '  <option value="">:::no vins found:::</option>'; 
        $vins .= '</select>';
        echo $vins;
}
    ?>

第16行是 if(mysql_num_rows($ result)){ 感谢任何帮助,非常感谢你!

1 个答案:

答案 0 :(得分:0)

可能是你的mysql_query失败了,$ result被绑定为FALSE。使用mysql_error()来检查出错的地方。