Afternoon,
I have a form that needs to enter mutiple values into one field, I know how to do it using a simple insert statement but I was advised to do it dynamically as shown below.
The problem is doing this dynamically doesn't bring this multiple selection field over it brings the word Array. Any thoughts or points in the right direction would be appreciated.
Thanks --Laura
The field looks like this:
<select name="CitrixApps[]" multiple>
<option>TRACCS</option>
<option>TMS2000</option>
<option>CARDS</option>
<option>CALM</option>
<option>MP2</option>
<option>TINA</option>
<option>TASK TRACCS</option>
<option>TRANSMAN</option>
</select>
//insert page//
//get the values from the Citrix field
$CA=$_POST['CitrixApps'];
for ($i=0; $i<count($CA); $i++){
$CitrixApps = $CitrixApps.",".$CA[$i];
}
echo $CitrixApps;
$host = "HQMSITADMIN01";
$database = "Security";
$table = " tblHolding";
function db_insert($tablename){
global $host;
global $database;
mssql_connect($host) or die("Cannot connect to the database.<br>");
mssql_select_db($database) or die("Cannot select the database.<br>");
$query = "INSERT INTO ".$tablename." SET ";
foreach($_POST as $field => $value){
if($field != "Submit"){
$fields[]=$field;
$values[]=$value;
}
}
$query = "INSERT INTO ".$tablename." (".implode(",",$fields).") VALUES('".implode("','",$values)."')";
echo $query."\n";
$result = mssql_query($query) or die("Cannot run query!");
return $result;
}
$dbinsert = db_insert($table);
echo $dbinsert;
?>