Certain Scheduled Task Script File not Working

Status
Not open for further replies.

rackem

Well-Known Member
I have the following code for a Scheduled Task.

PHP:
$db = JFactory::getDbo();
$processed = 0;
$p_names = array();
 
$query = ("SELECT `name_p1`, `name_p2` FROM `mps_fargo_import` WHERE 1");
$db->setQuery($query);
$rows =$db->loadObjectList();
 
foreach ($rows as $r) {
    array_push($p_names,$r->name_p1,$r->name_p2);
}
 
$p_names = array_unique($p_names);
$name_list = implode("'), ('", $p_names);
 
$query = ("INSERT INTO mps_fargo_import_names (`name`) VALUES ('$name_list')");
$db->setQuery($query);
$db->query();
$processed = $db->getAffectedRows();

All it does is pull a set of names from two rows of one table and inserts the set of unique names into another table. It performs as intended if I put it in the PHP Setup area of my scheduled task. However, if I wrap it into

PHP:
<?php
/* MOS Intruder Alerts */
defined('_JEXEC') or die('Restricted access');
 
/* My code here */
?>

in a PHP file in the plugins/fabrik_cron/php/scripts folder, then it won't run. All I get is a message saying 0 records updated.

I have other Scheduled Tasks that run from script files that work just fine. Any idea what might be going on here?
 
have you checked your php error logs?
Have you tried to add an exit; to the end of the script to see if there are any errors outputted to the browser?
by the way your code is not very secure, Never never never do things like :

Code:
VALUES ('$name_list')"

this is ripe for a potential SQL injection attack, always always use

Code:
$db->quote($name_list);


 
Thanks for the safety tip Rob.

I got it figured out. :) The problem was that there was a space in the file name. It was really tough to see because I had used underscores but had slipped a space in too. :oops:
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top