I'm trying to associate one item with many categories. I've got 1/2 of this working...the item info is submitted to my "ItemTable," but the corresponding category array data ($cats) is not being written to my "RelatedLookupTable" (I don't get any error messages...nothing happens).
Any help would be greatly appreciated.
Thanks.
if (isset($_POST['submititem'])) {
$cats = $_POST['cats'];
$itemname = $_POST['itemname'];
$description = $_POST['description'];
$brandid = $_POST['brandid'];
$categoryid = $_POST['categoryid'];
$subcategoryid = $_POST['subcategoryid'];
$image = $_POST['image'];
$imagewidth = $_POST['imagewidth'];
$imageheight = $_POST['imageheight'];
$imagealttext = $_POST['imagealttext'];
$pagetitle = $_POST['pagetitle'];
$metakeywords = $_POST['metakeywords'];
$metadescription = $_POST['metadescription'];
$display = $_POST['display'];
$sql = "INSERT INTO ItemTable SET
ItemName='$itemname', Description='$description',
BrandID='$brandid', CategoryID='$categoryid',
SubCategoryID='$subcategoryid', Image='$image',
ImageWidth='$imagewidth', ImageHeight='$imageheight',
ImageAltText='$imagealttext', PageTitle='$pagetitle',
MetaKeywords='$metakeywords',
MetaDescription='$metadescription', Display='$display',
DateAdded=CURDATE()";
if (@mysql_query($sql)) {
echo('<p><span class="main">Your item has been added.</span></p>');
} else {
echo('<p>Error adding submitted item: ' .
mysql_error() . '</p>');
}
$sql2 = mysql_query('SELECT ID FROM ItemTable');
mysql_query($sql2);
$jid = mysql_insert_id();
if ($cats == '') $cats = array();
$numCats = 0;
foreach ($cats as $catID) {
$sql3 = "INSERT IGNORE INTO RelatedLookupTable
SET ItemID=$jid, RelatedID=$catID";
$ok = @mysql_query($sql3);
if ($ok) {
$numCats = $numCats + 1;
} else {
echo('<p>Error inserting item into category' . $catID .
mysql_error() . '</p>');
}
}
}