-2

I'm getting this PHP Warning when im trying to register something on the companies website I work for. I didnt write this code so I'm not too sure what's going on but this is the error im getting - Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/mojo/public_html/warranty/warranty_reg_get_my_stock.php on line 16

and this is the code

<?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;
}
    ?>

Row #16 is if(mysql_num_rows($result)) { Any help is appreciated, thank you so much!

Giacomo1968
  • 24,837
  • 11
  • 67
  • 96
  • How do you know your query succeeded? You don't check the result of `mysql_query` at all. Also, read the manual for `mysql_query`. The `mysql_*` family of functions will be dead soon. Shame all the SQL-injection enabled by string concatenation won't be... – ta.speot.is Jul 07 '14 at 02:52

1 Answers1

0

It probably is that your mysql_query failed, and $result is binded with FALSE. Use mysql_error() to check what went wrong.

dangdis
  • 258
  • 2
  • 10