Hi all,
I am working on a script which uses a pick list allowing users to pick items from a list (single or multiple items) and insert them in to a table.
I am using code provided by PickList II script (aka Menu Swapper)- By Phil Webb (http://www.philwebb.com).
My form has 2 text select objects:
List one contains a list of items, list 2 would contain the items selected from list 1.
Once the list 1 items have been selects and moved to list 2 I want to save the list 2 items in to my table.
The code so far only allows one item in list 2 to be written to the table but not multiple items.
CODE'
<form method="post" name="form4" action="<?php echo $editFormAction; ?>">
<input name="member_id" type="hidden" value="<?php $_SESSION['_amember_user']['member_id']; ?>" />
<select multiple size="10" name="list1" class="packinglist" style="width:350" onDblClick="move(document.form4.list1,document.form4.list2)">
<?php
do {
?>
<option value="<?php echo $row_packinglista['description']?>"><?php echo $row_packinglista['description']?></option>
<?php
} while ($row_packinglista = mysql_fetch_assoc($packinglista));
$rows = mysql_num_rows($packinglista);
if($rows > 0) {
mysql_data_seek($packinglista, 0);
$row_packinglista = mysql_fetch_assoc($packinglista);
}
?>
</select>
<input type="button" onClick="move(this.form.list2,this.form.list1)" value="<<" id=button1 name=button1>
<input type="button" onClick="move(this.form.list1,this.form.list2)" value=">>" id=button2 name=button2></td>
<td><select multiple size="10" name="list2[]" id="list2" class="packinglist" style="width:350" ondblclick="move(document.form4.list2,document.form4.list1)">
</select
<input name="save1" type="submit" id="save1" value="Save" onClick="selectAll(document.form4.list2
<input type="hidden" name="MM_insert" value="form4" />
</form>
When the form is submitted it runs:
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
$list2 = $_POST['list2[]'];
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form4")) {
$insertSQL = sprintf("INSERT INTO baggage_packing_list (id, member_id, list2) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['member_id'] = $_SESSION['_amember_user']['member_id'], "int"),
GetSQLValueString($_POST['list2'] = $list2, "text"));
mysql_select_db($database_bag, $bag);
$Result1 = mysql_query($insertSQL, $bag) or die(mysql_error());
$insertGoTo = "pack_list_save_new.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
Can anyone see waht I am doing wrong.