justlukeyou Posted May 16, 2012 Share Posted May 16, 2012 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 https://forums.phpfreaks.com/topic/262629-cron-job-all-or-nothing/ Share on other sites More sharing options...
rythemton Posted May 16, 2012 Share Posted May 16, 2012 Are you getting any errors in your error logs? Running a PHP file as a CRON job should work fine. It would help if we at least had code to look at. Link to comment https://forums.phpfreaks.com/topic/262629-cron-job-all-or-nothing/#findComment-1346055 Share on other sites More sharing options...
justlukeyou Posted May 16, 2012 Author Share Posted May 16, 2012 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 https://forums.phpfreaks.com/topic/262629-cron-job-all-or-nothing/#findComment-1346063 Share on other sites More sharing options...
justlukeyou Posted May 16, 2012 Author Share Posted May 16, 2012 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 https://forums.phpfreaks.com/topic/262629-cron-job-all-or-nothing/#findComment-1346074 Share on other sites More sharing options...
mrMarcus Posted May 16, 2012 Share Posted May 16, 2012 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 https://forums.phpfreaks.com/topic/262629-cron-job-all-or-nothing/#findComment-1346078 Share on other sites More sharing options...
justlukeyou Posted May 16, 2012 Author Share Posted May 16, 2012 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. Link to comment https://forums.phpfreaks.com/topic/262629-cron-job-all-or-nothing/#findComment-1346084 Share on other sites More sharing options...
mrMarcus Posted May 16, 2012 Share Posted May 16, 2012 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 https://forums.phpfreaks.com/topic/262629-cron-job-all-or-nothing/#findComment-1346088 Share on other sites More sharing options...
justlukeyou Posted May 16, 2012 Author Share Posted May 16, 2012 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 https://forums.phpfreaks.com/topic/262629-cron-job-all-or-nothing/#findComment-1346101 Share on other sites More sharing options...
cpd Posted May 16, 2012 Share Posted May 16, 2012 Run the script using the CLI and see if it chucks out any unexpected errors. If not you need to start echoing stuff and debugging like that. Link to comment https://forums.phpfreaks.com/topic/262629-cron-job-all-or-nothing/#findComment-1346128 Share on other sites More sharing options...
rythemton Posted May 16, 2012 Share Posted May 16, 2012 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 https://forums.phpfreaks.com/topic/262629-cron-job-all-or-nothing/#findComment-1346135 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.