I have a simple form that's running some custom PHP to save some fields in my DB. Now, the form is working just fine when I load it as a page. But when I load it into a module, I am getting some strange behaviour.
I'm using the form to add categories to K2. The form has a bunch of fields, most are hidden, the only two textboxes are for the category name and description. The PHP script first checks if the name exists. If it does, it returns a message "sorry, this category already exists".
This works fine in both page and module instance of the form. Now the funny part:
If the category does not exist, it is added to the DB and a success message is returned. This works in the page instance but it fails in the module instance of the form. I'll paste the code below... I've got debug on maximum and I'm not even getting errors. Firebug's console doesn't show any issues either. I even added some echo statements AFTER the lines of code that fail, and all of the values I'm collecting are echoed just fine.
From what I can tell, the module is not evaluating 3 lines of the PHP script. Here's the code:
Any thoughts as to why the script works on the full page, but fails to run "resultInsert" when published as a module? I realize there's a lot of points of failure here, but I thought I'd just throw it out there to see if anyone had some ideas... even of just how to troubleshoot.
I'm using the form to add categories to K2. The form has a bunch of fields, most are hidden, the only two textboxes are for the category name and description. The PHP script first checks if the name exists. If it does, it returns a message "sorry, this category already exists".
This works fine in both page and module instance of the form. Now the funny part:
If the category does not exist, it is added to the DB and a success message is returned. This works in the page instance but it fails in the module instance of the form. I'll paste the code below... I've got debug on maximum and I'm not even getting errors. Firebug's console doesn't show any issues either. I even added some echo statements AFTER the lines of code that fail, and all of the values I'm collecting are echoed just fine.
From what I can tell, the module is not evaluating 3 lines of the PHP script. Here's the code:
$checkQuery = "SELECT * FROM db_k2_categories WHERE name='$name'";
$resultCheck = mysql_query($checkQuery);
if( mysql_num_rows($resultCheck) ) echo "<span class='alreadyExist'>Sorry $name already exists!</span>";
else {
$resultInsert = mysql_query("INSERT INTO db_k2_categories( id, parent, published, access, name, alias, description, params) VALUES('$id', '$parent', '$published', '$access', '$name', '$alias2', '$description', '$params')");
if($resultInsert) echo "New record saved successfully";
}
Any thoughts as to why the script works on the full page, but fails to run "resultInsert" when published as a module? I realize there's a lot of points of failure here, but I thought I'd just throw it out there to see if anyone had some ideas... even of just how to troubleshoot.