Hello, I'm not a php programmer but I'm trying to modify spawner.php to get categories in batch mode
because I've to add a lot of categories.
Example:
North America (cat)
Cars (sub-cat)
Design (sub-cat)
Architecture (sub-cat)
Food (sub-cat)
etc. etc... 40 sub-categories Asia (cat)
Cars (sub-cat)
Design (sub-cat)
Architecture (sub-cat)
Food (sub-cat)
etc. etc... 40 sub-categoriesThe same thing is for Europe, Hispano América, Oceania and Africa...everyone of these with the same 40 sub-categories...
So I modified spawner.php but when I try to upload a file with the category list I get this error: "There was an error while processing a database query"
Below the spawner2.php code:
<?php
define('IN_COPPERMINE', true);
require('include/init.inc.php');
if (!GALLERY_ADMIN_MODE) cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
pageheader('Category spawner');
starttable('100%', 'Category spawner');
if (count($_FILES)){
if ($_FILES['userfile']['error']) die('Upload error ' . $_FILES['userfile']['error']);
$data = file($_FILES['userfile']['tmp_name']);
$category = (int) $_POST['category'];
$description = addslashes($_POST['description']);
foreach ($data as $id => $category){
$result = cpg_db_query("INSERT INTO {$CONFIG['TABLE_CATEGORIES']} (`title`, `category`, `description`) VALUES ('$title', '$category', '$description')");
$status = mysql_affected_rows() ? "Category '$category' added" : "<font color=\"red\">Category'$category' not added</font>" ;
echo '<tr><td class="tableb" align="center">'.$status.'</td></tr>';
}
} else {
function get_subcat_data($parent, $ident = '')
{
global $CONFIG, $CAT_LIST;
$result = cpg_db_query("SELECT cid, name, description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent' AND cid != 1 ORDER BY pos");
if (mysql_num_rows($result) > 0) {
$rowset = cpg_db_fetch_rowset($result);
foreach ($rowset as $subcat) {
$CAT_LIST[] = array($subcat['cid'], $ident . $subcat['name']);
get_subcat_data($subcat['cid'], $ident . ' ');
}
}
}
$CAT_LIST = array();
$CAT_LIST[] = array(0, '* No category *');
get_subcat_data(0, '');
$cats = '<select name="category" class="listbox">';
foreach($CAT_LIST as $category) {
$cats .='<option value="' . $category[0] . '"' . ($cat == $category[0] ? ' selected': '') . ">" . $category[1] . "</option>\n";
}
$cats .= '</select>';
echo <<< EOT
<tr>
<td class="tableb" align="center">
<form action="spawner2.php" METHOD="post" enctype="multipart/form-data">
<p>Upload a file to import<input name="userfile" type="file" size="50" /></p>
<p>Default category description: <input type="text" name="description" size="50" value="" /></p>
<p>$cats</p>
<br />
<p><input type="submit" value="Spawn2" /></p>
</form>
</td>
</tr>
EOT;
}
endtable();
pagefooter();
?>
Please, Help