Page 1 of 1

Variables : writing to DB issues

Posted: Thu Nov 24, 2005 2:05 am
by facets
Hi All,

I'm having some trouble writing a value to my DB.
Can anyone see any issues with it?

It's writing the $id to the DB instead of $complaintType (SQL Insert code below.)

I've looked and played with this for hours and can't work it out.

TIA, wil

Code: Select all

<?

$productServiceList = array();

$sql_query = mysql_query("SELECT * FROM complaintType ORDER BY complaintType");

echo "<select name=\"complaintType\" onchange=\"showProdServ(this.options[this.selectedIndex].value)\">
<option value=\"\">-- Please Select --</option>\n";
while(list($complaintType, $id, $productService)=mysql_fetch_row($sql_query))
{
echo "<option value=\"$id\">$complaintType</option>\n";
$productServiceList[$id] = $productService;
}
echo "</select>

<span style=\"font-weight:bold;\" id=\"prodServ\"></span>

<script>
Viewer = document.getElementById(\"prodServ\");
ProdServList = new Array();";
foreach ($productServiceList as $id=>$prodServ)
echo "ProdServList[{$id}] = \"{$prodServ}\"\n";
//echo $productServiceList;

echo "

function showProdServ(val) {

   Viewer.innerHTML = ProdServList[val];

      if (ProdServList[val] == 'Product') {
         showdiv();
      }
      
      else {
         hidediv();
      }
}
</script>";

?>
-- insert Code --

Code: Select all

$result = mysql_query("INSERT INTO complaint(complaintType, detail, complaintNumber)
VALUES ('$complaintType', '$otherDetail', '$complaintNumber')");

Specify the fields order

Posted: Thu Nov 24, 2005 5:28 am
by anoopabose
Specify the fields order in the select query

Instaed of this Query SELECT * FROM complaintType ORDER BY complaintType
write like this
SELECT complaintType, id, productService FROM complaintType ORDER BY complaintType

Hope this will work...

What is the need of this statement inside the option value statement : $productServiceList[$id] = $productService;

Posted: Thu Nov 24, 2005 5:47 am
by facets
thanks for the reply.

the line you mentioned is populating the array $productServiceList
to use with the javascript.

what you suggested had the same result. it still writes the id to the DB instead of the complaintType.
if I change the $id to $complaintType it populates correctly but breaks the array.

echo "<option value=\"$id\">$complaintType</option>\n";

any other suggestions on how to write the contents of the select option instead of the value??