I’m looking to modify an existing module for personal use. Among other things, it provides tags that produce a form in a template which, when submitted, write form data to a table in the EE database.
I want to keep that functionality, but also write some of the same form data to a different table (exp_categories). I’ve written the add_categories function to do that, but I can’t seem to actually call the function correctly so it activates. (When I split the function up in to its parts and put it in an existing function within the module file, it writes to the categories table as it should, but the module’s original functionality doesn’t work.)
Anyway, here’s the function:
function add_categories ()
{
global $DB, $EXT, $FNS, $IN, $LANG, $LOC, $OUT, $PREFS, $REGX, $SESS, $TMPL;
$_POST = $REGX->xss_clean( $_POST );
$cat_query = $DB->query("SELECT AUTO_INCREMENT FROM information_schema.tables WHERE table_name='exp_categories' AND TABLE_SCHEMA='db_name' ORDER BY Auto_increment DESC LIMIT 1");
foreach($cat_query->result as $row){}
$cat_id = $row['AUTO_INCREMENT'];
$site_id = "1";
$group_id = "4";
$parent_id = "0";
$cat_name=$_POST['name']." Moderators";
$cat_title = $REGX->create_url_title($cat_name);
$cat_description = $_POST['description'];
$cat_image = "";
$cat_order = "0";
$data = array(
'cat_id' => $cat_id,
'site_id' => $site_id,
'group_id' => $group_id,
'parent_id' => $parent_id,
'cat_name' => $cat_name,
'cat_url_title' => $cat_title,
'cat_description' => $cat_description,
'cat_image' => $cat_image,
'cat_order' => $cat_order
);
$sql = $DB->insert_string('exp_categories', $data);
$DB->query($sql);
}Is there anything obvious that I’m doing wrong? This is going in to the mod.module_name.php file.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.