Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

mysql_fetch_array(): error


dfeenstra

Recommended Posts

Hello,

To make a linkpage on my website i have been intergrating an special link script into my shop, but now i seems that this script is giffing an error with the osc affiliate partner program.

For the linkscript i have to include a small part of code on top of all the pages where i want to show the links. I want to show links on many places on my site so i have put the piece of code on my main_page.tpl.php page (i'm using the BTS contribution).

When i put this piece of code directly after the body tag the link page is working fine, and also the most of the shop is working fine, only whe i log in as an affiliate i get the following error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/webusers/tom/www.manoes.nl/htdocs/shop/includes/boxes/affiliate.php on line 23

 

Line 23 of that page is:

allow = mysql_fetch_array(mysql_query("SELECT allow_template FROM affiliate_affiliate WHERE affiliate_id = '$affiliate_id'"));

 

the line i have included is:

 

CODE  
<?php $aldir="/partners/"; include($HTTP_SERVER_VARS['DOCUMENT_ROOT'].$aldir."display.php"); ?>

 

the content of the file display.php is:

<?

// get the autolinks include path
$alpath = $HTTP_SERVER_VARS['DOCUMENT_ROOT'] . $aldir;

include( $alpath . "al_initialize.php" );



////////////////////////////////////////////////
// UPDATE TAGS AND IMAGES
////////////////////////////////////////////////

// check if the site tags/images have been updated today
$res_site = @mysql_query( "SELECT updinterval, nextupdate FROM al_site WHERE login='$sitelogin' AND nextupdate<NOW() LIMIT 1" );

if( $res_site && @mysql_num_rows($res_site)>0 )
{
  // make sure we finish the code
  ignore_user_abort( true );

  // make sure the script doesn't timeout
  @set_time_limit( 600 );

  // get the previous update before we change it (for images)
  $prevupdate = date( "Y-m-d H:i:s", strtotime($site['nextupdate']) - ( $site['updinterval'] * 60 ) );

  // set the next update time to avoid double update
  $nextupdate = date( "Y-m-d H:i:s", mktime( date("H"), date("i")+$site['updinterval'], date("s"), date("m"), date("d"), date("Y") ) );
  mysql_query( "UPDATE al_site SET nextupdate='$nextupdate' WHERE login='$sitelogin'" );

  include( $alpath . "updatestats.php" );
  include( $alpath . "updatetags.php" );
  include( $alpath . "updateimages.php" );
}



////////////////////////////////////////////////
// CHECK DIRECT LINKING
////////////////////////////////////////////////

if( $CONF['direct_linking'] && isset($HTTP_REFERER) && $HTTP_REFERER!=""  )
{
  $ref_found = false;

  // extract the referer domain
  $parsedurl = parse_url( $HTTP_REFERER );
$host = eregi_replace( "www\.", "", $parsedurl['host'] );

// extract the current website domain
$siteparsedurl = parse_url( $site['url'] );
$sitehost = eregi_replace( "www\.", "", $siteparsedurl['host'] );

// check a domain is found and its different than the site domain
if( $host!="" && $host!=$sitehost )
{
 // get all referrers with this domain
 $res_ref = mysql_query( "SELECT * FROM al_ref WHERE url LIKE '%$host%' AND status=1" );
    $numref = mysql_num_rows( $res_ref );

 if( $numref==1 )
 {
   // only one ref with this domain found, take it
   $ref = mysql_fetch_assoc( $res_ref );
$ref_found = true;
 }
 elseif( $numref>1 )
 {
   $url_length = 0;
 
   while( $ref = mysql_fetch_assoc($res_ref) )
{
     // remove the www and http from both url
  $ref['url'] = str_replace( "http://", "", $ref['url'] );
  $ref['url'] = eregi_replace( "www\.", "", $ref['url'] );
  $HTTP_REFERER = str_replace( "http://", "", $HTTP_REFERER );
  $HTTP_REFERER = eregi_replace( "www\.", "", $HTTP_REFERER );
  
  // can the referrer url be found in the HTTP_REFERER?
  if( strstr( $HTTP_REFERER, $ref['url'] ) )
  {
    // is the url longer than the previous one?
 // (since we removed the http://www. it works
 // for both subdomains and subdirectories)
    if( strlen($ref['url']) > $url_length )
 {
   $longest_ref = $ref['login'];
   $ref_found = true;
 }
  }
}

// did one url match?
if( $ref_found )
{
  $res_ref = mysql_query( "SELECT * FROM al_ref WHERE login='$longest_ref' LIMIT 1" );
  $ref = mysql_fetch_assoc( $res_ref );
   }
 }
 
 if( $ref_found )
 {
   $i = $ref['login'];
   $directlink = true;

   include( $alpath . "in.php" );
 }
}
}

@mysql_close( $dbcnx );


////////////////////////////////////////////////
// SHOW TAG FUNCTION
////////////////////////////////////////////////

function showtag( $id )
{
  global $alpath;

  @include( $alpath . "tags/$id.php" );
}

?>

 

When i move the included line

<?php $aldir="/partners/"; include($HTTP_SERVER_VARS['DOCUMENT_ROOT'].$aldir."display.php"); ?>

to after the affiliate box code on my main_page.tpl.php page the error is away, but than the link script is not working anymore.

 

Hope someone can tell me how i can solve this problem.

 

Dani?l

Link to comment
Share on other sites

does your document root in your configure.php file in the format of:

 

/home/myusername/public_html/ or is it in a different format?

Link to comment
Share on other sites

does your document root in your configure.php file in the format of:

 

/home/myusername/public_html/ or is it in a different format?

 

My configure.php file looks like:

<?php
/*
 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

// Define the webserver and path parameters
// * DIR_FS_* = Filesystem directories (local/physical)
// * DIR_WS_* = Webserver directories (virtual/URL)
 define('HTTP_SERVER', 'http://www.manoes.nl'); // eg, http://localhost - should not be empty for productive servers
 define('HTTPS_SERVER', ''); // eg, https://localhost - should not be empty for productive servers
 define('ENABLE_SSL', false); // secure webserver for checkout procedure?
 define('HTTP_COOKIE_DOMAIN', 'www.manoes.nl');
 define('HTTPS_COOKIE_DOMAIN', '');
 define('HTTP_COOKIE_PATH', '/shop/');
 define('HTTPS_COOKIE_PATH', '');
 define('DIR_WS_HTTP_CATALOG', '/shop/');
 define('DIR_WS_HTTPS_CATALOG', '');
 define('DIR_WS_IMAGES', 'images/');
 define('DIR_WS_ICONS', DIR_WS_IMAGES . 'icons/');
 define('DIR_WS_INCLUDES', 'includes/');
 define('DIR_WS_BOXES', DIR_WS_INCLUDES . 'boxes/');
 define('DIR_WS_FUNCTIONS', DIR_WS_INCLUDES . 'functions/');
 define('DIR_WS_CLASSES', DIR_WS_INCLUDES . 'classes/');
 define('DIR_WS_MODULES', DIR_WS_INCLUDES . 'modules/');
 define('DIR_WS_LANGUAGES', DIR_WS_INCLUDES . 'languages/');

 define('DIR_WS_DOWNLOAD_PUBLIC', 'pub/');
 define('DIR_FS_CATALOG', '/home/webusers/tom/www.manoes.nl/htdocs/shop/');
 define('DIR_FS_DOWNLOAD', DIR_FS_CATALOG . 'download/');
 define('DIR_FS_DOWNLOAD_PUBLIC', DIR_FS_CATALOG . 'pub/');

Link to comment
Share on other sites

this:

<?php $aldir="/partners/"; include($HTTP_SERVER_VARS['DOCUMENT_ROOT'].$aldir."display.php");

 

when i translate it is:

/home/webusers/tom/www.manoes.nl/htdocs/shop//partners/

Link to comment
Share on other sites

this:

<?php $aldir="/partners/"; include($HTTP_SERVER_VARS['DOCUMENT_ROOT'].$aldir."display.php");

 

when i translate it is:

/home/webusers/tom/www.manoes.nl/htdocs/shop//partners/

 

Hi,

Thats not the problem, becouse the complete url therefor is not created by the config file but by $aldir witch is replaced by the real base url by the link script.

 

Ans whe i put the code on top of the page the schrip is working, but i only get an error by the affiliate box.

Link to comment
Share on other sites

The problem seems to be in another file as display.phh, in this file the file al_initialize.php is included and the code of that file is:

<?

 // make sure the file is not included twice
 if( !defined('INITIALIZE_INCLUDED') )
 {
   define( 'INITIALIZE_INCLUDED', 1 );

error_reporting( E_ALL ^ E_NOTICE );

   // check for hacking attempt
   if( strstr($alpath,"http://") || strstr($alpath,"https://") ) exit( "Invalid \$alpath variable" );
 
   include( $alpath . "al_functions.php" );

   if( get_magic_quotes_gpc() )
   {
     $HTTP_GET_VARS = stripslashes_array( $HTTP_GET_VARS );
  $HTTP_POST_VARS = stripslashes_array( $HTTP_POST_VARS );
  $HTTP_COOKIE_VARS = stripslashes_array( $HTTP_COOKIE_VARS );
   }
 
   if( !ini_get( "register_globals" ) || get_magic_quotes_gpc() )
   {
     @extract( $HTTP_GET_VARS );
     @extract( $HTTP_POST_VARS );
  @extract( $HTTP_SERVER_VARS );
  @extract( $HTTP_COOKIE_VARS );
  @extract( $HTTP_ENV_VARS );
   }

   // check (again) for hacking attempt
   if( strstr($alpath,"http://") || strstr($alpath,"https://") ) exit( "Invalid \$alpath variable" );
	 
   // include variables after to avoid them being overwritted
   include( $alpath . "variables.php" );
 
   $dbcnx = mysql_connect( $mysql_host, $mysql_user, $mysql_pass )
     or exit( "Error! Can't connect to MySQL server. Please check the variables.php files" );

   mysql_select_db( $mysql_db )
     or exit( "Error! Can't find '$mysql_db' database. Please make sure it exists" );

   $res_site = mysql_query( "SELECT * FROM al_site WHERE login='$sitelogin' LIMIT 1" );
   if( mysql_num_rows($res_site)==0 ) exit( "Error! Could not find a site with login '$sitelogin' on the database" );
   $site = mysql_fetch_array( $res_site );
  
   // load all the configs in an array
   $CONF = loadconf();
   if( !$CONF ) exit( "Could not load the general configurations from database!" );
 }
	 
?>

and the following part of that code can be the problem, becouse when i remove that part of code the error is away:

    $dbcnx = mysql_connect( $mysql_host, $mysql_user, $mysql_pass )
     or exit( "Error! Can't connect to MySQL server. Please check the variables.php files" );

   mysql_select_db( $mysql_db )
     or exit( "Error! Can't find '$mysql_db' database. Please make sure it exists" );

   $res_site = mysql_query( "SELECT * FROM al_site WHERE login='$sitelogin' LIMIT 1" );
   if( mysql_num_rows($res_site)==0 ) exit( "Error! Could not find a site with login '$sitelogin' on the database" );
   $site = mysql_fetch_array( $res_site );
  
   // load all the configs in an array
   $CONF = loadconf();
   if( !$CONF ) exit( "Could not load the general configurations from database!" );

 

Who can tel me how to solve this problem without removing the part of code above becouse i expect that the script needs that code.

 

Dani?l

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...