Jump to content

de-bug problem


Lassie

Recommended Posts

i'm tying to establish that my function is returning the right values, but my de bug line fails to print.
Can anyone help please?
code is
function display_dl_link($cart,$product_id)
{

// query database for all details for a particular book

  if (!$product_id || $product_id=='')
    return false;
$connection = db_connect();   
  $query = "select dl_link from products where product_id='$product_id'";
  $result = mysql_query($query);
  if (!$result)
    return false;
   
  while ($row = mysql_fetch_assoc($result)){

echo $row['dl_link'];//print to establish record pulled from db

}
}
Thanks,
lassie.
Link to comment
https://forums.phpfreaks.com/topic/31827-de-bug-problem/
Share on other sites

There are two things to checl. 1) Is your query causing an error and 2) is it returning any results.

Try this:
[code]<?php
function display_dl_link($cart,$product_id) {

// query database for all details for a particular book

  if (!$product_id || $product_id=='') {
      return false;
  }
  $connection = db_connect();   
  $query = "select dl_link from products where product_id='$product_id'";
  $result = mysql_query($query);
  if (!$result) {
      mysql_error();
      return false;
  }

  if (mysql_num_rows($result)==0) {
      echo "There were 0 results";
  } else {
      while ($row = mysql_fetch_assoc($result)){
        echo $row['dl_link'];//print to establish record pulled from db
      }
  }
}

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/31827-de-bug-problem/#findComment-147580
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.