moiseszaragoza
12-01-2007, 09:48 AM
I am trying to insert multiple values from a select multiple field but i am only getting one.
I have a JS that gives me the values but its not passing to my Insert Statement.
JS
<script type="text/javascript">
function getNumbers(f){
var chieldComp='';
var sel=f.CompanyID.options;
for(var i=0; i<sel.length; i++) {
if(sel[i].selected){
chieldComp+=sel[i].value+',';
}
}
this.CompanyID.value=chieldComp
alert(chieldComp)
}
</script>
FIELD
<form id="addUsers" name="addUsers" onSubmit="return getNumbers(this)" method="POST" action="<?php echo $editFormAction; ?>">
<? $NumberOfRows = mysql_num_rows($getChieldCompanys); ?>
<select name="CompanyID" size="<?php echo($NumberOfRows); ?>" multiple="multiple" id="CompanyID">
<?php
do {
?>
<option value="<?php echo $row_getChieldCompanys['CompanyID']?>"><?php echo $row_getChieldCompanys['CompanyName']?></option>
<?php
} while ($row_getChieldCompanys = mysql_fetch_assoc($getChieldCompanys));
$rows = mysql_num_rows($getChieldCompanys);
if($rows > 0) {
mysql_data_seek($getChieldCompanys, 0);
$row_getChieldCompanys = mysql_fetch_assoc($getChieldCompanys);
}
?>
</select>
</form>
Insert Query
$insertSQL = sprintf("INSERT INTO Users (CompanyID) VALUES (%s)",
GetSQLValueString($_POST['CompanyID'], "int"));
Function GetSQLValueString()
<?
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
I have a JS that gives me the values but its not passing to my Insert Statement.
JS
<script type="text/javascript">
function getNumbers(f){
var chieldComp='';
var sel=f.CompanyID.options;
for(var i=0; i<sel.length; i++) {
if(sel[i].selected){
chieldComp+=sel[i].value+',';
}
}
this.CompanyID.value=chieldComp
alert(chieldComp)
}
</script>
FIELD
<form id="addUsers" name="addUsers" onSubmit="return getNumbers(this)" method="POST" action="<?php echo $editFormAction; ?>">
<? $NumberOfRows = mysql_num_rows($getChieldCompanys); ?>
<select name="CompanyID" size="<?php echo($NumberOfRows); ?>" multiple="multiple" id="CompanyID">
<?php
do {
?>
<option value="<?php echo $row_getChieldCompanys['CompanyID']?>"><?php echo $row_getChieldCompanys['CompanyName']?></option>
<?php
} while ($row_getChieldCompanys = mysql_fetch_assoc($getChieldCompanys));
$rows = mysql_num_rows($getChieldCompanys);
if($rows > 0) {
mysql_data_seek($getChieldCompanys, 0);
$row_getChieldCompanys = mysql_fetch_assoc($getChieldCompanys);
}
?>
</select>
</form>
Insert Query
$insertSQL = sprintf("INSERT INTO Users (CompanyID) VALUES (%s)",
GetSQLValueString($_POST['CompanyID'], "int"));
Function GetSQLValueString()
<?
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>