Im in need of some assitance in order to implement a multiselect selection box and then inserting the choices as seperate records into a table in a MySql DB.
For the form, Im pulling information from two tables, then inserting it into a third as seperate records, based on what is chosen in the multiselect box.
From table 1 , Im pulling the last record inserted.
From table 2 , Im pulling in the memberid and membername (multiselect box)
For table 3, should insert whatever is selected in the multiselect box as seperate records from table 1.
Ie, if last record was #45
Multiselect box chosen were id's 3,4,6,9 (shown name of member, but only their id will be inserted into the table)
Table 3 would result in :
45 | 3
45 | 4
45 | 6
45 | 9
I am currently modifying an existing code to make this work properly . Below are code snippets, along with the html Im working with (which is being pulled frm a template)
I KNOW that the get_multiple function is where the problem lies. How do i change it so that it takes the resulting choices and puts it into an array that can be called up from get_multiple(); ?
<?
//===============================
// Get Param function
//===============================
function get_param($param_name)
{
global $HTTP_POST_VARS;
global $HTTP_GET_VARS;
$param_value = "";
if(isset($HTTP_POST_VARS[$param_name]))
$param_value = $HTTP_POST_VARS[$param_name];
else if(isset($HTTP_GET_VARS[$param_name]))
$param_value = $HTTP_GET_VARS[$param_name];
return $param_value;
}
//===============================
// Get Multiple Function
//===============================
function get_multiple($param_name)
{
global $HTTP_POST_VARS;
global $HTTP_GET_VARS;
$Where = "";
if (isset($HTTP_GET_VARS[$param_name]))
{
$array_p = $HTTP_GET_VARS[$param_name];
}
if (isset($HTTP_POST_VARS[$param_name]))
{
$array_p = $HTTP_POST_VARS[$param_name];
}
if ($array_p)
{
$size_p = count($array_p);
for ($i = 0; $i< $size_p+1; $i++)
{
if (strlen($Where) == 0)
$Where .= " ". $param_name. "=". ToSQL($array_p[$i], "Number");
else
$Where .= " OR ".$param_name. "=". ToSQL($array_p[$i], "Number");
}
}
return $Where;
}
//===============================
// Record Form Queries
//-------------------------------
function participant_action($sAction)
{
global $db;
global $tpl;
global $sForm;
global $sparticipantErr;
$bExecSQL = true;
$sActionFileName = "";
$sParams = "?";
$sWhere = "";
$bErr = false;
$pPKid = "";
$fldeventid = "";
$fldwho = "";
//===============================
// Event begin
//===============================
$sActionFileName = "admin_event.php";
$sParams .= "eventid=" . urlencode(get_param("Trn_eventid"));
//===============================
// CANCEL action
//===============================
if($sAction == "cancel")
{
header("Location: " . $sActionFileName . $sParams);
exit;
}
//===============================
// Build WHERE statement
//===============================
if($sAction == "update" || $sAction == "delete")
{
$pPKid = get_param("PK_id");
if( !strlen($pPKid)) return;
$sWhere = "id=" . tosql($pPKid, "Number");
}
//===============================
// Load all form fields into variables
//===============================
$fldeventid = get_param("eventid");
$fldwho = get_param("who");
//===============================
// Create SQL statement
//===============================
switch(strtolower($sAction))
{
case "insert":
$sSQL = "insert into participants (" .
"eventid," .
"who)" .
" values (" .
tosql($fldeventid, "Number") . "," .
tosql($fldwho, "Number") .
")";
break;
case "update":
$sSQL = "update participants set " .
"eventid=" . tosql($fldeventid, "Number") .
",who=" . tosql($fldwho, "Number");
$sSQL .= " where " . $sWhere;
break;
case "delete":
$sSQL = "delete from participants where " . $sWhere;
break;
}
//===============================
// Execute SQL statement
//===============================
if(strlen($sparticipantErr)) return;
if($bExecSQL)
$db->query($sSQL);
header("Location: " . $sActionFileName . $sParams);
exit;
}
?>
<html>
<form method="POST" action="{FileName}" name="participant">
<table class="FormTABLE">
<tr>
<td class="FormHeaderTD" colspan="2"><font class="FormHeaderFONT">{FormTitle}</font></td>
</tr>
<!--BeginparticipantError-->
<tr>
<td class="DataTD" colspan="2"><font class="DataFONT">{sparticipantErr}</font></td>
</tr>
<!--EndparticipantError-->
<tr>
<td class="FieldCaptionTD"><font class="FieldCaptionFONT">eventid</font></td>
<td class="DataTD">
<input type="text" name="eventid" maxlength="11" value="{eventid}" size="11">
</td>
</tr>
<tr>
<td class="FieldCaptionTD"><font class="FieldCaptionFONT">who</font></td>
<td class="DataTD">
<select multiple size=10 name="who[]">
<option value="{ID}" {Selected}>{Value}</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="hidden" value="insert" name="FormAction">
<input type="submit" value="Insert" onclick="document.participant.FormAction.value = 'insert';">
<input type="hidden" value="update" name="FormAction"/>
<input type="submit" value="Update" onclick="document.participant.FormAction.value = 'update';"/>
<input type="submit" value="Delete" onclick="document.participant.FormAction.value = 'delete';"/>
<input type="submit" value="Cancel" onclick="document.participant.FormAction.value = 'cancel';"/>
<input type="hidden" name="FormName" value="participant"/>
<input type="hidden" name="Trn_eventid" value="{Trn_eventid}"/>
<input type="hidden" name="PK_id" value="{PK_id}"/>
<input type="hidden" name="id" value="{id}"/>
</td>
</tr>
</table>
</form>
</html>