I have a form which has two multiselect fields, one containing a list of reasons someone called, the other a list of who the call was about - theoretically you could call about 5 different things, which all apply to 5 people (or more for each). The table is set up to store one event for one person at a time, so I am trying to figure out the best way to use a foreach loop to make the database insert as painless as possible...
I only worked out one of the foreach loops so far, but it still doesn't work (it will insert one record if i remove the foreach loop though)
<?php
require_once ("DB.php");
require_once ("global_inc.php");
$db = DB::connect($dsn);
if( DB::isError($db) ) {
die ($db->getMessage());
}
$con_meth = $db->quote($_POST["con_meth"]); //only one of these - indicates method of contact
$subcon_meth = $_POST["subcon_meth"]; //can be multiple - shows reason for contact
$childsel = $db->quote($_POST["childsel"]); //can be multiple - shows person contact was about
$notes = $db->quote($_POST["notes"]); //only one note to cover all reasons and persons
foreach($subcon_meth as $sub) {
$sql = "INSERT INTO tbl_Activities (ID,ActivityID,SubActivityID,ChildID,Social_WorkerID,FamilyID,Start_Date,Description) VALUES ('',$con_meth,'$sub',$childsel,'','',Now(),$notes)";
$result = $db->query($sql);
echo $sql;
}
?>
am i missing something???