Ok... I have been trying to get this form to work for a while now... there are probably some simple mistakes here, but after hours of staring, I can't seem to find them....
Here is my insert syntax
$SQL="INSERT INTO Business VALUES('','$b_name','$b_address','$b_city','$Menu_pict')";
$result=mysql_query($SQL,$dB);
// insert into BUSINESS_CATEGORY table
$_insertedBusinessID=last_insert_id();
$SQL2="INSERT INTO Business_Category Values('$_insertedBusinessID','$val')";
foreach($_POST['parent'] as $val)
{
$result2=mysql_query($SQL2,$db);
}
Here is my update syntax
$SQL="UPDATE Business SET b_name='$b_name', b_address='$b_address', b_city='$b_city', Menu_pict='$Menu_pict' WHERE bid=$bid";
$result=mysql_query($SQL,$dB);
// update BUSINESS_CATEGORY table
foreach($_POST['parent'] as $val)
{
mysql_query ("UPDATE Business_Category SET bid='$bid' WHERE cid='$val'");
}
here is my form
<form name="author_admin" method="post" action="<?php echo $PHP_SELF;?>" onSubmit="return verify()" enctype="multipart/form-data">
<table width="600" border="0" cellspacing="2" cellpadding="2" class="content">
<TR><TD>
<table width="400" border="0" cellspacing="2" cellpadding="2" class="content">
<TR><TD>Business: </TD><TD><input type="text" name="b_name" value="<?php echo $b_name;?>"></TD></TR>
<TR><TD valign="top">Address: </TD><TD><input type="text" name="b_address" value="<?php echo $b_address;?>"></TD></TR>
<TR><TD>City/State/Zip: </TD><TD><input type="text" name="b_city" value="<?php echo $b_city;?>"> <input type="text" name="b_state" value="<?php echo $b_state;?>" size="3"><input type="text" name="b_zip" value="<?php echo $b_zip;?>" size="6"></TD></TR>
<TR><TD>County: </TD><TD><input type="text" name="b_county" value="<?php echo $b_county;?>"></TD></TR>
<TR><TD>Phone: </TD><TD><input type="text" name="b_phone" value="<?php echo $b_phone;?>"></TD></TR>
<TR><TD>Contact(First/last): </TD><TD><input type="text" name="b_contact_first" value="<?php echo $b_contact_firts;?>"> <input type="text" name="b_contact_last" value="<?php echo $b_contact_last;?>"></TD></TR>
<TR><TD>Websote: </TD><TD><input type="text" name="b_website" value="<?php echo $b_website;?>"></TD></TR>
<TR><TD>Email: </TD><TD><input type="text" name="b_email" value="<?php echo $b_email;?>"></TD></TR>
<TR><TD>Picture: </TD><TD><?php if ($t != 4) { echo "<A HREF=\"../images/food/$Menu_pict\" onclick=\"NewWindow(this.href,'Photo','350','350','no');return false\">$Menu_pict</A>"; }?><BR><input type="file" name="Menu_pict"> (optional)</TD></TR>
<TR><TD></TD><TD><input type="submit" name="submit" value="Insert/Update"><P>
<input type="hidden" name="t" value="<?php echo $t_value;?>">
<input type="hidden" name="bid" value="<?php echo $bid;?>">
<a href="<?php echo $PHP_SELF;?>">Insert New Records</a></TD></TR>
</TABLE>
</TD><TD VALIGN="top" ALIGN="right">
Categories<BR>
<?php
$sql_select ="SELECT DISTINCT name FROM Category";
$sql_select_result =mysql_query ($sql_select,$dB) or die ("Couldn't execute 'select' query.");
echo "<select name=\"parent[]\" id=\"parent\" MULTIPLE>";
echo "<option value=\"PRIMARYCATEGORY\">PRIMARYCATEGORY</option>";
while ( $row =mysql_fetch_array ($sql_select_result )){
if ($parent == $row['name']) {
echo '<option value="'.$row['name'].'" selected>'.$row['name'].'</option>';
}
else {
echo '<option value="'.$row['name'].'">'.$row['name'].'</option>';
}
}
echo "</select>"
?>
</TD></TR></TABLE>
</form>