Here's what I've done so far, not sure if this is gonna work. Seems like it should.
if ($id == 0) {
$add_query = "INSERT INTO companies (company_name) VALUES ('$company')";
$id = mysql_insert_id();
$result = mysql_query($add_query);
foreach($cat_array as $val) {
$add_cat_query = "INSERT INTO comp_cats (company_id,category_id) VALUES ($id,$val)";
$result = mysql_query($add_cat_query);
}
$status = "New Company added!";
} else {
$upd_query = "UPDATE companies SET company_name='$company' WHERE company_id=$id";
$result = mysql_query($upd_query);
$del_cat_query = "DELETE FROM comp_cats WHERE company_id = $id";
$result = mysql_query($del_cat_query);
foreach ($cat_array as $val) {
$add_cat_query = "INSERT INTO comp_cats (company_id,category_id) VALUES ($id,$val)";
$result = mysql_query($add_cat_query);
}
$status = "Company Update Successful!";
}
However, when I submit the form, it doesn't submit my categories in a comma delimited list. Here's what I've got...
<select name=category size=5 multiple id=category></select>
I select multiple categories in the list and rather than submitting 1,4,7 the form submits 7, whatever the last id was. I thought multiple made it submit all the values. But I think if I can get that to work, then I'm almost done.
Anybody know?
Thanks,
Wil