Hello-
I have some code, below, which is supposed to SELECT an array of id's from one table then INSERT them into another table, one per row. In my code, the SELECT functions okay, but I can't get the INSERT to work. I get an error on the second foreach: "Warning: Invalid argument supplied for foreach()" and nothing is inserted.
When I echo the "$rowID", it returns a correct string. (The 'MainCategoryID' and 'busid' come from sessions variables)
Any help would be appreciated. Thanks.
$subcat=$_POST['subcat'];
foreach( $subcat as $k ){$sql= "Select * from Category where MasterCategoryID='$maincategoryID' and ID='$k'";
$result= mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
$rowID=$row["ID"];
echo $rowID;
}
}
foreach($rowID as $m )
{
$sql= "INSERT INTO BusinessGuide SET ID='$busid', UserInfoID='$busid', CategoryID='$m'";
}