Jump to content

Finishing script then erroring


homchz

Recommended Posts

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
[code]
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);
            }
        }
    }
[/code]

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

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:
[code]
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))
[/code]

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
Link to comment
https://forums.phpfreaks.com/topic/11713-finishing-script-then-erroring/
Share on other sites

Yeah, I had to chave it to this
[code]
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);
            }
  
    }
[/code]

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.