Insert Multiple Records
I am trying to insert multiple records from a form. I can get it to insert the records but, it is not looping through the number of designated data elements selected. What I need for it to happen is for every district selected, it will add a record for every data element selected. Attached is a screenshot of the page.
Here is the insert code:
<?php
if (isset($_POST["submit"]) || isset($_POST["submit_x"])) {
$element = $_POST['data_elementID'];
foreach($element as $name=>$value) {
$InsertQuery = new WA_MySQLi_Query($sdpc_i);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "district_data_elements";
$InsertQuery->bindColumn("districtID", "i", ((isset($_POST["districtID"]))?$_POST["districtID"]:"") , "WA_NULL");
$InsertQuery->bindColumn("softwareID", "i", "".((isset($_POST["softwareID"]))?implode(",",$_POST["softwareID"]):"") ."", "WA_NULL");
$InsertQuery->bindColumn("data_elementID", "i", ((isset($_POST["data_elementID"]))?$_POST["data_elementID"]:"") , "WA_NULL");
$InsertQuery->saveInSession("");
$InsertQuery->execute(); }
$InsertGoTo = "manage_agreements_state.php?state=".$_GET['state'] ."&districtID=".$_GET['districtID'] ."";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
?>
Here is the form code:
<form method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-xs-5">
<select name="from[]" id="search" class="form-control" size="15" multiple="multiple">
<?php
while(!$category->atEnd()) { //dyn select
?>
<option value="<?php echo($category->getColumnVal("data_elementID")); ?>"><?php echo($category->getColumnVal("element_name")); ?></option>
<?php
$category->moveNext();
} //dyn select
$category->moveFirst();
?>
</select>
</div>
<div class="col-xs-2">
<button type="button" id="search_rightAll" class="btn btn-block"><i class="glyphicon glyphicon-forward"></i></button>
<button type="button" id="search_rightSelected" class="btn btn-block"><i class="glyphicon glyphicon-chevron-right"></i></button>
<button type="button" id="search_leftSelected" class="btn btn-block"><i class="glyphicon glyphicon-chevron-left"></i></button>
<button type="button" id="search_leftAll" class="btn btn-block"><i class="glyphicon glyphicon-backward"></i></button>
</div>
<div class="col-xs-5">
<select name="data_elementID[]" id="search_to" class="form-control" size="15" multiple="multiple">
</select>
</div>
</div>
<p> </p>
<h4>Please select the district(s) that use this resource that you would like to assign these data elements to:</h4>
<div class="row">
<div class="col-xs-5">
<select name="from[]" id="search2" class="form-control" size="15" multiple="multiple">
<?php
while(!$districts_selected->atEnd()) { //dyn select
?>
<option value="<?php echo($districts_selected->getColumnVal("districtID")); ?>"><?php echo($districts_selected->getColumnVal("district_name")); ?></option>
<?php
$districts_selected->moveNext();
} //dyn select
$districts_selected->moveFirst();
?>
</select>
</div>
<div class="col-xs-2">
<button type="button" id="search2_rightAll" class="btn btn-block"><i class="glyphicon glyphicon-forward"></i></button>
<button type="button" id="search2_rightSelected" class="btn btn-block"><i class="glyphicon glyphicon-chevron-right"></i></button>
<button type="button" id="search2_leftSelected" class="btn btn-block"><i class="glyphicon glyphicon-chevron-left"></i></button>
<button type="button" id="search2_leftAll" class="btn btn-block"><i class="glyphicon glyphicon-backward"></i></button>
</div>
<div class="col-xs-5">
<select name="districtID[]" id="search2_to" class="form-control" size="15" multiple="multiple">
</select>
</div>
</div>
<input type="hidden" name="softwareID[]" id="softwareID" value="<?php echo $_GET['softwareID']; ?>" />
<br><br>
<input type="image" src="images/save.png" name="submit" id="submit" alt="Save" />
</form>
