Help, errors connecting but the code seems right?
Posted: Wed Jan 12, 2011 10:13 pm
Hi, I have a cron job set up to run a file daily but I get the following errors from the cron, when it runs.
I have double checked the database, username and password variables and are correct, I changed the permissions for the user to "ALL"
here is the page it is supposed to run
here is the include page
Code: Select all
Warning: mysql_connect(): Access denied for user 'batman25'@'localhost' (using
password: NO) in /home/batman25/public_html/cron/dailyjobs_anp.php on line 18
Warning: mysql_select_db(): Access denied for user 'batman25'@'localhost' (using
password: NO) in /home/batman25/public_html/cron/dailyjobs_anp.php on line 19
Warning: mysql_select_db(): A link to the server could not be established in
/home/batman25/public_html/cron/dailyjobs_anp.php on line 19
Warning: mysql_query(): Access denied for user 'batman25'@'localhost' (using
password: NO) in /home/batman25/public_html/cron/dailyjobs_anp.php on line 80
Warning: mysql_query(): A link to the server could not be established in
/home/batman25/public_html/cron/dailyjobs_anp.php on line 80
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in
/home/batman25/public_html/cron/dailyjobs_anp.php on line 81I have double checked the database, username and password variables and are correct, I changed the permissions for the user to "ALL"
here is the page it is supposed to run
Code: Select all
<?php
# Variables
#***********
$basePath = "/home/batman25/public_html/";
#*******************************************************
#Section to Get Daily rates from XE.com Starts HERE
#*******************************************************
# including all needed files
$constPath = $basePath.'includes/constants.php';
$from = "USD";
$amt=1;
$today = date('Y-m-d');
# estabilshing connection
mysql_connect($host,$user,$pass);
mysql_select_db($db);
$curobj = new currency();
$rateobj = new currency();
//checks if the integration with XE.com is true
if($const_getCurrencyRatesFromXe == "1")
{
# For integration with xe.com
$currencyPath = $basePath."currency_converter.inc.php";
include_once($currencyPath);
# Gets base currency code
$base = $default_currency_code;
$baseCurr = new CURRENCYCONVERTER(1,$base,$from);
$baseValue = $baseCurr->convert();
# Gets all currencies from the table
$result = $curobj->GetAllCurrencies($base);
if($result)
{
for($i=0; $i<count($curobj->curCode); $i++)
{
$to = $curobj->curCode[$i];
$curr = new CURRENCYCONVERTER($amt,$to,$from);
$newAmt = $curr->convert();
$currAmt = number_format(($newAmt / $baseValue),2);
$rateobj->FindCurrentRate($to);
$presentRate = $rateobj->rate;
if($presentRate != $currAmt)
{
$sql_rate = "INSERT INTO partners_currency_relation (relation_currency_code, relation_value, relation_date) ".
" VALUES( '$to', $currAmt, '$today') ";
$res_rate = mysql_query($sql_rate);
}
}
}
}
#*******************************************************
# Rates Section Ends HERE
#*******************************************************
# Finding and paying Recurring Commission Starts HERE
#*******************************************************
$today = date('Y-m-d');
//Gets commissio0n to be recurred for the current day
$sql = "SELECT * FROM partners_recur, partners_transaction, partners_joinpgm, partners_merchant, partners_affiliate ".
" WHERE recur_balanceamt > 0 AND recur_status='Active' AND ".
" date_format(now(),'%Y-%m-%d') >= date_format(DATE_ADD(recur_lastpaid ,INTERVAL recur_period MONTH),'%Y-%m-%d') ".
" AND recur_transactionid = transaction_id AND joinpgm_id = transaction_joinpgmid AND ".
" merchant_id=joinpgm_merchantid AND merchant_status='approved' AND affiliate_id=joinpgm_affiliateid AND affiliate_status='approved' ";
$res = mysql_query($sql);
if(mysql_num_rows($res) > 0)
{
//for each commission to be recurred today
while($row = mysql_fetch_object($res))
{
$recurId = $row->recur_id;
$transId = $row->recur_transactionid;
$totalComm = $row->recur_totalcommission;
$recurPercent = $row->recur_percentage;
$recurPeriod = $row->recur_period;
$recurBalance = $row->recur_balanceamt;
$totalSubsaleComm = $row->recur_total_subsalecommission;
$balanceSubsale = $row->recur_balance_subsaleamt;
$transStatus = $row->transaction_status;
$merId = $row->joinpgm_merchantid;
$affId = $row->joinpgm_affiliateid;
$parentid = $row->transaction_parentid;
//Calculates commission amount and subsale commission amount
$currComm = ($totalComm / $recurPercent) * 100;
if($currComm > $recurBalance)
$currComm = $recurBalance;
$currBalanceComm = $recurBalance - $currComm;
$currSubsale = ($totalSubsaleComm / $recurPercent) * 100;
if($currSubsale > $balanceSubsale)
$currSubsale = $balanceSubsale;
$currBalanceSubsale = $balanceSubsale - $currSubsale;
//if Transaction Status is approved perform the Money transaction to the Merchant an dAffiliate balances
if($transStatus == 'approved')
{
//Checking Merchant Balance
$cutOfff = $minimum_amount; //getting minimum balance for merchant
$sql_mer = "SELECT * FROM merchant_pay WHERE pay_merchantid = $merId ";
$res_mer = @mysql_query($sql_mer);
//if Merchant balance exists
if(mysql_num_rows($res_mer) > 0)
{
$row_mer = mysql_fetch_object($res_mer);
$merchant_bal = $row_mer->pay_amount;
//if Merchnat do not have minimum Balance in his accont then set the Transaction status as pending
// so that it can be added to the affiliate balance later
if(($merchant_bal - $currComm) <= $cutOfff)
{
$transStatus = 'pending';
}
else // if merchant has minimum balance in his account
{
$merchant_bal = $merchant_bal - $currComm;
//getting Affiliate payment details
$sql_aff = "SELECT * FROM affiliate_pay WHERE pay_affiliateid = $affId ";
$res_aff = @mysql_query($sql_aff);
//If affiliate account exists update account
if(mysql_num_rows($res_aff) > 0)
{
$row_aff = mysql_fetch_object($res_aff);
$affiliate_bal = $row_aff->pay_amount;
$affiliate_bal = $affiliate_bal + $currComm;
$sql_affPay = "UPDATE affiliate_pay SET pay_amount = $affiliate_bal WHERE pay_affiliateid = $affId ";
$res_affPay = @mysql_query($sql_affPay);
}
else // Add account record for the Affiliate
{
$sql_affPay = "INSERT INTO affiliate_pay SET pay_amount = $affiliate_bal, pay_affiliateid = $affId ";
$res_affPay = @mysql_query($sql_affPay);
}
$sql_merPay = "UPDATE merchant_pay SET pay_amount=$merchant_bal WHERE pay_merchantid = $merId ";
$res_merPay = @mysql_query($sql_merPay);
//Adds Subsale Commission to Parent Affiliate and Subtracts it from the Admin Amount
$admin_curamount = 0;
if($currSubsale > 0)
{
//Gets details of Admin Account
$sql_admin = "SELECT * FROM admin_pay ";
$res_admin = @mysql_query($sql_admin);
//If admin record exists perform subsale commission calculation
if(mysql_num_rows($res_admin) > 0)
{
$row_admin = mysql_fetch_object($res_admin);
$admin_curamount = $row_admin->pay_amount;
$admin_curamount = $admin_curamount - $currSubsale;
// Gets Parent Affiliate balance
$sql_subsale = "SELECT * FROM affiliate_pay WHERE pay_affiliateid = $parentid ";
$res_subsale = @mysql_query($sql_subsale);
//If Parent affiliate accountexists updates the account balance
if(mysql_num_rows($res_subsale) > 0)
{
$row_subsale = mysql_fetch_object($res_subsale);
$parent_curamt = $row_subsale->pay_amount;
$parent_curamt = $parent_curamt + $currSubsale;
$sql_subsalePay = "UPDATE affiliate_pay SET pay_amount=$parent_curamt WHERE pay_affiliateid = $parentid ";
$res_subsalePay = @mysql_query($sql_subsalePay);
}
else // Adds new account balance for the parent Affiliate
{
$sql_subsalePay = "INSERT INTO affiliate_pay SET pay_amount=$parent_curamt, pay_affiliateid = $parentid ";
$res_subsalePay = @mysql_query($sql_subsalePay);
}
//Updates the administrator balance
$sql_adminPay = "UPDATE admin_pay SET pay_amount=$admin_curamount ";
$res_adminPay = @mysql_query($sql_adminPay);
}
else //Add new account for the Administrator
{
$sql_adminPay = "INSERT INTO admin_pay SET pay_amount=$admin_curamount ";
$res_adminPay = @mysql_query($sql_adminPay);
}
}
}
}
else //If merchant do not have any account set recurring staus as pending
{
$transStatus = 'pending';
}
}
//Updates the recur record with the new date of payment and the new balance commisison and subsale comm
$sql_recur = "UPDATE partners_recur SET ".
" recur_balanceamt = '$currBalanceComm' , ".
" recur_lastpaid = '$today' , ".
" recur_balance_subsaleamt = '$currBalanceSubsale' ".
" WHERE recur_id = '$recurId' ";
$res_recur = @mysql_query($sql_recur);
//Adds new record for the Recurring payment
$sql_recurpay = "INSERT INTO partners_recurpayments SET ".
" recurpayments_recurid = '$recurId' , ".
" recurpayments_date = '$today' , ".
" recurpayments_amount = '$currComm' , ".
" recurpayments_status = '$transStatus' , ".
" recurpayments_subsaleamount = '$currSubsale' ";
$res_recurpay = @mysql_query($sql_recurpay);
}
}
#*******************************************************
# Recurring Commission Ends HERE
#*******************************************************
#*******************************************************
# Class Currency
#*******************************************************
class currency
{
/*-------------------------------------------------------------------------------------------
Function to find the currency details of currrencies other tahn present Base Currency
Created By : SMA
Created On : 8-AUG-2006
-------------------------------------------------------------------------------------------*/
function GetAllCurrencies($base)
{
$sql = "SELECT * FROM partners_currency WHERE currency_code != '$base' ";
$res = mysql_query($sql);
if(mysql_num_rows($res) > 0)
{
while($row = mysql_fetch_object($res))
{
$this->curCode[] = $row->currency_code;
$this->curCaption[] = $row->currency_caption;
}
return true;
}
else
return false;
}
/*-------------------------------------------------------------------------------------------
Function to get the present rate of a currency with respect to the Base currency
Created By : SMA
Created On : 8-AUG-2006
-------------------------------------------------------------------------------------------*/
function FindCurrentRate($currency)
{
$sql = "SELECT * FROM partners_currency_relation ".
" WHERE relation_currency_code = '$currency' ORDER BY relation_date DESC ";
$res = mysql_query($sql);
if(mysql_num_rows($res) > 0)
{
$row = mysql_fetch_object($res);
$this->rate = $row->relation_value;
}
else
$this->rate = 0;
return;
}
}
#*******************************************************
# END Class Currency
#*******************************************************
?>here is the include page
Code: Select all
<?php
#-----------------------------------------------------------------------------
# Databse parametrs
#-----------------------------------------------------------------------------
$host ='localhost';
$user ='batman25_anp';
$pass ='anp';
$db ='batman25_anp';
#-----------------------------------------------------------------------------
# Payment parametrs
#-----------------------------------------------------------------------------
//Added on 4-AUG-2006 for default Currency
$default_currency_code = "USD";
$default_currency_caption = "$";
//For Automatic Updates of Currency Rates From XE.com
$const_getCurrencyRatesFromXe = "1";
//Added on 19-JUNE for Fraud Protection
$fraudsettings_recentclick = "0";
$fraudsettings_clickseconds = "12";
$fraudsettings_clickaction = "do not save";
$fraudsettings_recentsale = "0";
$fraudsettings_saleseconds = "10";
$fraudsettings_saleaction = "decline";
$fraudsettings_decline_recentsale = "1";
$fraudsettings_login_retry = "2";
$fraudsettings_login_delay = "10";
//Added on 16-JUNE-2006
$const_imp_rate =0;
$normal_user =0;
$advanced_user =0;
$admin_clickrate =13.95;
$admin_salerate =13.95;
$admin_leadrate =13.95;
$minimum_amount =0;
$minimum_withdraw =20;
$program_fee = 0;
$program_type =2;
$program_value ="7 month";
$membership_type =2;
$membership_value ="0 month";
//Maximum amount limits for merchants/affiliates/admin
$merchant_maximum_amount = 1000;
$affiliate_maximum_amount = 1000;
$admin_maximum_amount = 4000;
//Commission type (flatrate/percentage) for click/lead/sale
global $admin_clickrate_type;
global $admin_leadrate_type;
global $admin_salerate_type;
$admin_clickrate_type = "percentage";
$admin_leadrate_type = "percentage";
$admin_salerate_type = "percentage";
# icon width and Height
global $icon_height;
$icon_height = "16";
global $icon_width;
$icon_width = "16";
$timeZoneArray = array( "Newzealand Time(-12)"
,"Midway Isles, Samoa (-11)"
,"Hawaii (-10)"
,"AKST - Alaska Standard Time(-9)"
,"PST - Pacific Standard Time(-8)"
,"MST - Mountain Standard Time(-7)"
,"CST - Central Standard Time(-6)"
,"EST - Eastern Standard Time(-5)"
,"SA West - Atlantic Time(-4)"
,"SA East - East Brasil Time (-3)"
,"Middle Atlantic (-2)"
,"Island Time (-1)"
,"GMT - Greenwitch Meridian Time (0)"
,"CET - Central European Time (+1)"
,"EET - East European Time (+2)"
,"Irak, Kuwait, Russia(+3)"
,"Mauritius, Kazachstan (+4)"
,"West Asia (+5)"
,"Central Asia (+6)"
,"Indo China Time (+7)"
,"Chinese Shore Time (+8)"
,"JST - Japan Standard Time (+9)"
,"AUS - Australian Time(+10)"
,"Central Pacifik (+11)"
,"Newzealand Time (12)"
);
#-----------------------------------------------------------------------------
# Site Title and no of rec
#-----------------------------------------------------------------------------
$title = "Digital-Xpay";
$lines = 3;
#-----------------------------------------------------------------------------
# Site Url
#-----------------------------------------------------------------------------
$secured_site_url = "http://www.digital-xpay.com";
$track_site_url = "http://www.digital-xpay.com";
#-----------------------------------------------------------------------------
# Cooments
#-----------------------------------------------------------------------------
$norec = "No Records of this type" ;
$blank = "Invalid Entry. Please fill in all required fields";
$emailerr = "Please Enter a valid E-mail Id";
$emailexist = "E-mail Id already Exists";
$currArray = array('Yen'=>'¥','Pound'=>'£','Swiss Francs'=>'CHF','Euro'=>'€');
reset ($_GET);
foreach ($_GET as $key => $value)//to stripslash all get variables
{
$value = stripslashes(trim($value));
$_GET[$key]=$value;
}
reset ($_POST);
foreach ($_POST as $key => $value)//to stripslash all posted variables
{
$value = stripslashes(trim($value));
$$key = $value;
//echo "$key=>$value <br/>";
}
reset ($_GET);
reset ($_POST);
?>