Hello.

Im getting this error on a product page on my website

Quote

'Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/supremew/public_html/catalog/osc/products_new.php on line 89'

?>
    <tr>
    <td width="<?php echo SMALL_IMAGE_WIDTH + 10; ?>" valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $products_new['products_image'], $products_new['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>'; ?></td>
    <td valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '"><b><u>' . $products_new['products_name'] . '</u></b></a><br>' . TEXT_DATE_ADDED . ' ' . tep_date_long($products_new['products_date_added']) . '<br>' . TEXT_MANUFACTURER . ' ' . $products_new['manufacturers_name'] . '<br><br>' . TEXT_PRICE . ' ' . $products_price; ?></td>
    <!--Start JLG Disable Buy Now and Shopping Cart-->
    <?php
    ?>
    <tr>
    <td width="<?php echo SMALL_IMAGE_WIDTH + 10; ?>" valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $products_new['products_image'], $products_new['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>'; ?></td>
    <td valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '"><b><u>' . $products_new['products_name'] . '</u></b></a><br>' . TEXT_DATE_ADDED . ' ' . tep_date_long($products_new['products_date_added']) . '<br>' . TEXT_MANUFACTURER . ' ' . $products_new['manufacturers_name'] . '<br><br>' . TEXT_PRICE . ' ' . $products_price; ?></td>
    <!--Start JLG Disable Buy Now and Shopping Cart-->
    <?php
    $nononline_items = array();
    $sql = "SELECT products_id FROM products WHERE disable_addtobasket='Y'";
    $result = mysql_query($sql);
    while($id = mysql_fetch_array($result,MYSQL_ASSOC)){
    array_push($nononline_items,$id['products_id']);
    }
    if (in_array($products_new['products_id'],$nononline_items)){
    echo ("<td align=\"right\">". NON_ONLINE_ITEM ."</td>");
    }
    else{
    echo "<td align=\"right\" valign=\"middle\" class=\"main\">";
    echo '<a href="' . tep_href_link(FILENAME_PRODUCTS_NEW, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $products_new['products_id']) . '">' . tep_image_button('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</a>';
    echo "</td>";
    }
    ?>
    <!--End JLG Disable Buy Now and Shopping Cart-->
    $sql = "SELECT products_id FROM products WHERE disable_addtobasket='Y'";
    $result = mysql_query($sql);
    while($id = mysql_fetch_array($result,MYSQL_ASSOC)){
    array_push($nononline_items,$id['products_id']);
    }
    if (in_array($products_new['products_id'],$nononline_items)){
    echo ("<td align=\"right\">". NON_ONLINE_ITEM ."</td>");
    }
    else{
    echo "<td align=\"right\" valign=\"middle\" class=\"main\">";
    echo '<a href="' . tep_href_link(FILENAME_PRODUCTS_NEW, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $products_new['products_id']) . '">' . tep_image_button('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</a>';
    echo "</td>";
    }
    ?>
    <!--End JLG Disable Buy Now and Shopping Cart-->

In red is line 89

Can anyone help? I really have no idea what to edit


Thanks.

Dani AI

Generated

That warning means the value you pass to mysql_fetch_array() is not a valid result resource — in practice mysql_query() returned false (a failure) and you handed that boolean to mysql_fetch_array(). was right that the result set is the starting point. Below are focused, practical steps to find and fix the problem, plus a safer pattern to avoid the warning.

Start checklist (fast):

  • Confirm your DB connection actually succeeded before running queries.
  • Find the query that builds the list of products you use to populate $nononline_items and check it immediately after mysql_query() — don’t call mysql_fetch_* unless the query succeeded.
  • Remove the duplicated query block in the posted code (you run the same query twice); build the array once and reuse it.
  • Avoid displaying raw DB errors to visitors; log them instead.

Safer pattern (example — switch to mysqli when possible):

$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!$conn) { error_log('DB connect error: ' . mysqli_connect_error()); }

$res = mysqli_query($conn, $sql);
if (!$res) {
  error_log('Query failed: ' . mysqli_error($conn) . ' SQL: ' . $sql);
} else {
  $nononline_items = array();
  while ($row = mysqli_fetch_assoc($res)) {
    $nononline_items[] = $row['products_id'];
  }
  mysqli_free_result($res);
}

Extra notes tied to this thread: ’s file is osCommerce-based (products_new.php). If you prefer the platform API, use the built-in DB wrapper (the tepdb helpers) so you stay consistent with osCommerce’s connection and error handling. Finally, if the site runs PHP 7+, the old `mysql_extension is removed — plan to migrate tomysqliorPDO` to avoid future breakage.

Recommended Answers

All 6 Replies

Please look for pre-solved problems before reposting them.

Do i just paste this code in my php files?

1.
      $query = 'SELECT * FROM `security` LIMIT 0 , 30';
   2.
      $result = mysql_query($query, $conn);
   3.
      if (mysql_numrows($result) == 0)
   4.
      {
   5.
      echo "Result set is EMPTY";
   6.
      } else if (!$result) {
   7.
      echo "Result set is NULL";
   8.
      } else {
   9.
      echo "Result set is VALID";
  10.
      $row = mysql_fetch_assoc($result);
  11.
      $a = array_search($user, $row);
  12.
      echo $a;
  13.
      }

Pretty much, all you need to do is replace the sql with your own and put all of your data handling where I've specified:

$query = '[B]YOUR SQL HERE[/B]';
      $result = mysql_query($query, $conn);
      if (mysql_numrows($result) == 0)
      {
      echo "Result set is EMPTY";
      } else if (!$result) {
      echo "Result set is NULL";
      } else {
      echo "Result set is VALID";
      $row = mysql_fetch_row($result);
      [B]YOUR DATA HANDLING HERE[/B]      
      }

Good luck.

Sorry, Im still a novice, what do you mean by data handling?

I take it my 'SQL' is the database?

Data handling is what you want to do to your data one you've extracted it from the database, display it in a table, perform calculations etc.

Your SQL is the statement you execute to get the data out of the database (eg "SELECT * FROM table_name WHERE condition bla bla bla)

On a side note, osCommerce is one of the most complex third party programs I have had the chance to work with, and if you are a php novice it might be a better idea to cut your teeth on something a little simpler, or at least avoid customising it as much as possible.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.