Variables : writing to DB issues

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Variables : writing to DB issues

Post 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')");
User avatar
anoopabose
Forum Newbie
Posts: 2
Joined: Thu Nov 24, 2005 5:02 am
Location: India ,Kerala

Specify the fields order

Post 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;
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post 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??
Post Reply