Jump to content

Cron Job - All or Nothing?


justlukeyou

Recommended Posts

I am trying to set up a Cron Job. When I run it says that it is inserted. However when I enter my database nothing is in there.

 

Does each part column of a cron job need to be correct for it all to work? For example if I have the code for column corrrect but one wrong will it now work at all?

 

I am a bit lost as to why it says inserted but nothing actually goes into my database.

 

I can manually enter information into the database I can echo it. But I cant Cron Job it in there.

Link to comment
Share on other sites

Thanks mate,

 

This is the code.  I have had it working in the past but now it just says inserted but doesn't give any errors.  Is there anyway I can put error messages in determine why it is not entering?

 

 

else {

        switch($xmlReader->name) {

            case "merchant":

                echo "New merchant: " . $xmlReader->getAttribute("name") . "<br />";

                $merchant = mysql_real_escape_string($xmlReader->getAttribute("name"));

                break;

            case "prod":

                $dom = new DOMDocument();

                $domNode = $xmlReader->expand();

                $element = $dom->appendChild($domNode);

                $domString = utf8_encode($dom->saveXML($element));

                if(trim($domString) != "") {

                    $prod = new SimpleXMLElement($domString);

                    $id = $prod->attributes();

                    $id = $id['id'];

                    $link = $prod->uri->mLink;

                    $description = mysql_real_escape_string($prod->text->name);

                    $fulldescription = mysql_real_escape_string($prod->text->desc);

                    $image = $prod->uri->awImage;

                    $retailprice = $prod->price->rrp;

                    $sellprice = $prod->price->buynow;

                    if($id) {

                        if($sellprice > 0 && $retailprice > 0) {

                            $discount = 100 - ($sellprice / $retailprice * 100);

                        } else {

                            $discount = 0;

                        }

                        echo "New product: #" . $id . " - " . $description . " - Discount: " . $discount . "%" . (($discount > 90.01 || $discount < 0) ? " (Not inserted)" : " (Inserted)") . "<br />" . $fulldescription . "<br /><br />";

                        if($discount > 49.99 && $discount < 90.01) {

                            $query = mysql_query("SELECT * FROM productdbase WHERE id = '".$id."'");

                            if(mysql_num_rows($query) > 0) {

                                $query = mysql_query("UPDATE productdbase SET awImage = '".$image."', link = '".$link."', description = '".$description."', fulldescription = '".$fulldescription."', price = '".$sellprice."', discount = '".round($discount)."', merchant = '".$merchant."' WHERE id = '".$id."'");

                            } else {

                                $query = mysql_query("INSERT INTO productdbase (id, awImage, link, description, fulldescription, price, discount, merchant) VALUES ('".$id."', '".$image."', '".$link."', '".$description."', '".$fulldescription."', '".$sellprice."', '".round($discount)."', '".$merchant."')");

                            }

                            if($query) {

                                echo $id . " has been inserted.<br />";

                            } else {

                                echo $id . " could not be inserted because: " . mysql_error() . ".<br />";

                            }

                        }

                    } else {

                        echo "Could not retrieve the product information.<br />";

                    }

                }

                break;

Link to comment
Share on other sites

This my database, I'm not making a silly mistake here am I.  However I can echo from it when I manually put content into it to test the echo.

 

ID int(255) No   

link varchar(999) No   

description varchar(999) No   

fulldescription varchar(999) No   

awImage varchar(999) No   

sellprice varchar(999) No   

discount varchar(255) No   

merchant varchar(255) No   

Link to comment
Share on other sites

silly mistake

 

ID int(255) No

 

No, nothing silly about an INT(255) lmao.

 

When I run it says that it is inserted

 

If you are running a CRON job, nothing will be printed to the browser.  Where/how is it saying that the record has been inserted?

 

 

Link to comment
Share on other sites

Hi,

 

When I go to domain.com/cron.php it returns a report which tells me what the results are.

 

What should this be please: INT(255) lmao

 

I am looking to introduce an ID which increased by 1 for each line.

 

 

 

Sorry, I shouldn't have laughed.  See Integer Types for more info.  Or present your table schema to the MySQL board for relevant help as your structure is out of whack.

 

Perhaps your CRON is running first, you're then checking the results in the browser, but the INSERT query is no longer running as the record in question has already been inserted and the UPDATE query is now running.  Could that be the case?

 

Regardless of whether your INSERT or UPDATE query are firing, you're returning a message that reads that the record has been 'inserted'.  Perhaps you should integrate separate messages for each query type, ie.

 

UPDATE query:

 

echo $id . " has been updated.<br />";

 

INSERT query:

 

echo $id . " has been inserted.<br />";

 

So you can be clear as to what is happening.

Link to comment
Share on other sites

Many thanks

 

It has come up with this error:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /public_html/cron.php on line 98

 

which is for this...but the error doesn't really mean anything to me.

 

if(mysql_num_rows($query) > 0) {

 

 

Link to comment
Share on other sites

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /public_html/cron.php on line 98

It means the $query is returning FALSE rather than a query resource. Change the line to read:

if( $query && mysql_num_rows($query) > 0)

See if that makes a difference.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.