Jump to content


Photo

Finishing script then erroring


  • Please log in to reply
2 replies to this topic

#1 homchz

homchz
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts
  • LocationLee, New Hampshire

Posted 11 June 2006 - 02:49 PM

This one is wierd.

My script is running and updating my db, but I am getting an error afterward, and an unusual <br/> tag???

The funtion inside of the class jobs
function pay_cron()
    {
        $sql = mysql_query("SELECT uid, gold, salary FROM p_users WHERE occupation != '0'")or die(mysql_error());
        while($results = mysql_fetch_object($sql))
        {
            $uid[]    = $results->uid;
            $gold[]   = $results->gold;
            $salary[] = $results->salary;
            
            $num      = count($uid);
                        
            for($i=0; $i<$num; $i++)
            {
                $pay = ($gold[$i]+$salary[$i]);
                
                $sql = mysql_query("UPDATE p_users SET gold = '$pay' WHERE uid = '$uid[$i]'")or die(mysql_error());
                $update = mysql_query($sql);
            }
        }
    }

How I am calling the funtion for testing:
<?php
include('classes/class_jobs.php');
$daily_pay = new jobs;
$daily_pay->pay_cron();
?>

Then I am getting this warning "after" the script excutes.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/flightfe/public_html/new/projects/pirate/source/classes/class_jobs.php on line 127
[/quote]

Line 126 & 127:
126: $sql = mysql_query("SELECT uid, gold, salary FROM p_users WHERE occupation != '0'")or die(mysql_error());
127: while($results = mysql_fetch_object($sql))

any thoughts??

Edit: never mind

This always happens, as soon as I see the reveiw the code when i post it. I see my issue.

Thanks anyway

Josh

#2 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 11 June 2006 - 02:50 PM

try running the sql query on the database outside the code..if it works there...weird because no strings in the query. You are connected to the db right?
z..z..z..z..z..z..z..z..

#3 homchz

homchz
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts
  • LocationLee, New Hampshire

Posted 11 June 2006 - 02:51 PM

Yeah, I had to chave it to this
function pay_cron()
    {
        $sql = mysql_query("SELECT uid, gold, salary FROM p_users WHERE occupation != '0'")or die(mysql_error());
        while($results = mysql_fetch_object($sql))
        {
            $uid[]    = $results->uid;
            $gold[]   = $results->gold;
            $salary[] = $results->salary;
            
            $num      = count($uid);
             }               
             for($i=0; $i<$num; $i++)
            {
                $pay = ($gold[$i]+$salary[$i]);
                
                $sql = mysql_query("UPDATE p_users SET gold = '$pay' WHERE uid = '$uid[$i]'")or die(mysql_error());
                $update = mysql_query($sql);
            }
  
    }





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users