Trouble putting $_POST value into a MySQL Query
Posted: Thu Mar 19, 2009 3:02 am
I am new to PHP but not to coding and I am at a loss. I can't get this query to work properly. The general purpose of the code is selecting a record from a MySQL table into a combobox on the first form and using that record to get it's relational children put into another combobox on the called form. I am trying to put the $_POST value into the Query but it does not return any records. It should return 1 exact match. I have gotten the $_POST value from a combobox on the previous form which called this code. When I echo the $baseProduct it shows up correctly so the $_POST value is there. I am not looping through the array because I should only have one record. I think it is a syntax problem in the query. Any ideas would be appreciated.
Code: Select all
<?php $Selected_DB = mysql_select_db ("highdollaritems");?>
<?php
$baseProduct = $_POST["selectedProduct"];
echo $baseProduct;// Test to see if value is there
$baseProductQuery = "SELECT * FROM BaseProducts WHERE BaseProducts.SWProductName = '$baseProduct'";
$result1 = mysql_query($baseProductQuery);
$row1 = mysql_fetch_assoc($result1);
$baseProductUId = $row1['UniqueID'];
echo $baseProductUId; // Test to see if value is there
?>
<?php
$query = "SELECT * FROM `Accessories` WHERE Accessories.UniqueID = '$baseProductUId'";
$result2 = mysql_query($query);
while ($row = mysql_fetch_array($result2)) {
$UniqueID[] = $row['UniqueID'];
$SWAccessoryID[] = $row['SWAccessoryID'];
$SWAccessoryName[] = $row['SWAccessoryName'];
$AccessoryDescription[] = $row['AccessoryDescription'];
$Price[] = $row['Price'];
}
?>
<SELECT name = "SWAccessoryName" size="1" id="Combobox1">
<?php
$option = "<option VALUE=\"Select a Pool Package\">Please select a Pool Package</option> \n";
for ($i = 0; $i < COUNT($SWAccessoryName); $i++) {
$option .= "<option ";
$option .= "value=\"$SWAccessoryName[$i] $$Price[$i]\">$SWAccessoryName[$i] $$Price[$i]</option> \n";
}
echo $option;
?>
</SELECT>
<INPUT name="SubmitForm" type="submit" class="orderInputFields" value="Create Sales Order"></TD>