How to resolve this php error with mysql_fetch_object()

Discussion in 'PHP' started by Mackos, Jul 11, 2010.

  1. #1
    Hello!
    I don't know why, I didn't change anything on my website, but yesterday it started to show on my site this error:
    Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /homez.228/mirrory/www/site/dailyroutine.php on line 56

    Line 56 is:
    $rowCheck = mysql_fetch_object($retCheck) ;

    and file dailyroutine.php :
    
    <?php
    
    
          function ChangeStaus($minimum_amount)
          {
          //geting records from table
          $pay_sql = "select * from merchant_pay where pay_amount < $minimum_amount  ";
          $pay_ret = @mysql_query($pay_sql);
          //echo mysql_error();
          //checking for each records
          if(@mysql_num_rows($pay_ret)>0)
          {
                  while($pay_row=@mysql_fetch_object($pay_ret))
                  {
                         $id= trim(stripslashes($pay_row->pay_merchantid));
    
                         //geting records from table
                         $sql1 = "update partners_merchant set merchant_status='empty' where merchant_id='$id' and merchant_status not like 'NP'";
                         $ret  = @mysql_query($sql1);
                   }
          }
          }
    
          function getProgramFee(){
    
            $sql = "SELECT program_merchantid,program_id,program_fee,program_value,program_type FROM partners_program  WHERE program_status='active'";
            $ret = @mysql_query($sql);
    
            if(mysql_num_rows($ret)>0){
               while($row = mysql_fetch_object($ret)){
                     $merid   		= $row->program_merchantid;
                     $id   		    = $row->program_id;
                     $prgm_fee	 	= trim($row->program_fee);
                     $prgm_value  	= $row->program_value;
                     $prgm_type	   	= $row->program_type;
    
                     if(($prgm_type == "0")){
       					 $prgm_fee	   	= $program_fee;
                         $prgm_value	= $program_value;
                         $prgm_type		= $program_type;
      				 }
    
                    	 if($prgm_type==2){
    
    	                    $sqlFee = "SELECT adjust_date AS DATE FROM partners_fee WHERE adjust_no = '$id' and adjust_action like '%programFee' order by adjust_date desc";
    	                    $retFee = mysql_query($sqlFee);
    
                            if(mysql_num_rows($retFee)>0){
    	                         $rowFee   =  mysql_fetch_object($retFee) ;
    	                         $date     = $rowFee->DATE;
    
                                 $sqlCheck = "SELECT date_format(date_add('$date',INTERVAL $prgm_value),'%H/%i/%s/%d/%m/%y') as R";
    	                         $retCheck = mysql_query($sqlCheck);
    
    	                         $rowCheck =  mysql_fetch_object($retCheck) ;
    	                         $d =  $rowCheck->R;
    
                                 if(!Compare($d)){
                                   payProgramFee($merid,$prgm_fee,$id);
                                 }
                           } 
    	             }
                 }
              }
          }
          function setPending(){
            $sql = "SELECT * FROM partners_fee WHERE adjust_flag='pending' and adjust_action like 'programFee' ";
            $ret = mysql_query($sql);
             if(mysql_num_rows($ret)>0){
               while($row   = mysql_fetch_object($ret)){
                 $amount    = $row->adjust_amount;
                 $mid       = $row->adjust_memberid;
                 $id        = $row->adjust_id;
                 $pgmid     = $row->adjust_no;
    
                 closeFee($id,$mid,$pgmid,$amount);
               }
             }
          }
    
    
    //--------------------------------------------------------
    //  Function to get and pay Monthly membership Fee
    //--------------------------------------------------------
    function payMembership(){
    
       /*
       checks whethre mebership type is recurring or not.
       */
       if($membership_type==2){
    
            /*
             if recurring gets all merchants accounts
            */
            $sql = " SELECT * FROM partners_merchant ";
            $ret = mysql_query($sql);
    
            if(mysql_num_rows($ret)>0){
            	while( $row = mysql_fetch_object($ret)){
    
                			# Merchant Id
                			$id   = $row->merchant_id;
                            $type = $row->merchant_type;
    
                            /*
                             Checks the type of user
                             and set the fee accodingly
                            */
                            if($type=="normal")  $fee = $normal_user;
                            else                 $fee = $advanced_user;
    
                            /*
                              Get the last Payment Date
                            */
                      		$sqlFee = "SELECT adjust_date AS DATE FROM partners_fee WHERE adjust_memberid = '$id' and adjust_action like 'register' order by adjust_date desc LIMIT 0,1";
    	                    $retFee = mysql_query($sqlFee);
    
                            if(mysql_num_rows($retFee)>0){
    	                         $rowFee   =  mysql_fetch_object($retFee) ;
    	                         $date     = $rowFee->DATE;
    
                                 /*
                                  checks whether the date next payment date has expired
                                 */
                                 $sqlCheck = "SELECT  date_format(date_add('$date',INTERVAL $membership_value),'%H/%i/%s/%d/%m/%y') as R";
    	                         $retCheck = mysql_query($sqlCheck);
    
    	                         $rowCheck =  mysql_fetch_object($retCheck) ;
    	                         $d 	   =  $rowCheck->R;
    
                                 /*
                                  if expired do payment
                                 */
                                 if(!Compare($d)){
                                   payMembershipFee($id,$fee);
                                 }
    
    
    	                    }
                }
            }
       }
    }
    
    /*
     Do Pending Membership Paymets
    */
     function setMemPending(){
            $sql = "SELECT * FROM partners_fee WHERE adjust_flag='pending' and adjust_action like 'register' ";
            $ret = mysql_query($sql);
             if(mysql_num_rows($ret)>0){
               while($row   = mysql_fetch_object($ret)){
                 $amount    = $row->adjust_amount;
                 $mid       = $row->adjust_memberid;
                 $id        = $row->adjust_id;
                 $pgmid     = $row->adjust_no;
    
                 closeMemFee($id,$mid,$amount);
               }
             }
    }
    
    function
     Compare($ipblock)
    {
    //comparing date
           $dtarray       =explode("/",$ipblock);
           $iphour        =$dtarray[0];
           $ipminute      =$dtarray[1];
           $ipsecond      =$dtarray[2];
           $ipdate        =$dtarray[3];
           $ipmonth       =$dtarray[4];
           $ipyear        =$dtarray[5];
    
     //current
           $d=date("d");
           $m=date("m");
           $y=date("Y");
           $h=date("H");
           $i=date("i");
           $s=date("s");
    
           $today=mktime($h,$i,$s,$m,$d,$y);
           $ipblock= mktime($iphour,$ipminute,$ipsecond,$ipmonth,$ipdate,$ipyear);
    
           if($ipblock>$today)
              return true;
           else
              return false;
    
    }
    ?>
    PHP:

     
    Mackos, Jul 11, 2010 IP
  2. patrickchewing

    patrickchewing Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have you changed the structure of your database at all? It doesn't look like that is your first query to the database, but if it is and you are getting that error, I would check your database name, user name, and password.
     
    patrickchewing, Jul 11, 2010 IP
  3. Mackos

    Mackos Well-Known Member

    Messages:
    364
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Nope. I didn't changed anything in database ...
     
    Mackos, Jul 11, 2010 IP
  4. Oxi

    Oxi Peon

    Messages:
    78
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Change line 54 i.e.

    $retCheck = mysql_query($sqlCheck);
    PHP:
    to

    $retCheck = mysql_query($sqlCheck) or die (mysql_error ());
    PHP:
    and then refresh the page and post the error message given here.
     
    Oxi, Jul 11, 2010 IP
  5. Mackos

    Mackos Well-Known Member

    Messages:
    364
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #5
    Well yes - it's database error, somehow I changed php file that send wrong command into database, now It's working good, thanks!
     
    Mackos, Jul 12, 2010 IP