从下拉列表更新SQL查询

时间:2014-04-11 23:25:45

标签: php sql drop-down-menu

我有一个应该更新我的SQL查询的下拉菜单。如果我从选择HTML创建下拉列表,它工作正常,但是当我从PHP数组运行它时,它不会在发布时选择其他选项(尽管如果我从中手动选择数组元素,它会选择它们)该计划。

此外,我在整个程序中放置了几个echo语句以进行故障排除,我可以清楚地看到正在选择正确的项目,并且它已经发布到SQL代码,但它&# 39; s只是不正常。

例如,我的echo语句打印出SQL查询

sql = SELECT * from finished_goods WHERE BrandDesc LIKE'%Alma Rosa%'

工作正常。但如果我使用下拉菜单选择" alere"它没有用。

sql = SELECT * from finished_goods WHERE BrandDesc LIKE'%Alere%'

<table>
  <form id = "myform" method="post" action="">
  <th>FG id : <input type = "text" name = "finished_goods_id2"/></th>
  <th>Product No : <input type = "text" name = "ProdNo"/></th>
  <th>Product Name : <input type = "text" name = "ProductName"/></th>
  <th>Product Group : <input type = "text" name = "ProductGroup"/></th>


  <!--    this code puts a drop down in, but it doesnt update the form  -->


<th>Brand : <!--  this select statement works fine
 <select name = "BrandDesc"> 
<option value = "Alma Rosa">Alma Rosa text</option>
<option value = "Alere">Alere</option>
<option value = "Hitching Post">Hitching Post text</option>
</select>
-->
<?php  // this array replaces the select dropdown, but doesn't update
$name = 'BrandDesc'; 
$selected = 0;
  $options = array( 'Alma Rosa', 'Alere', 'Hitching Post' );
echo dropdown( $name, $options, $selected ); 
?>

<th>Varietal : <input type = "text" name = "Varietal"/></th>
<th>Vintage : <input type = "text" name = "VintYear"/></th>
<th>Quantity :</th>
<th><input type = "submit" name = "send" value = "Submit"/></th>
<tr></tr>

<?php 

// new connection
$conn = dbConnect('read', 'thereal8_work', 'PDO'); // database for online
$brandNo = 0;  // sets the brand so that it displays the first select statement
$brandAccess = $options[$brandNo];  
echo " first Brand Access = ".$brandAccess. " <br>";
if ($_POST['BrandDesc']) {
echo " base brandNo = ".$brandNo. "<br>";
$brandNo = $_POST['BrandDesc'];
echo " posted brandNo = ".$brandNo. " <br> ";
echo "options in the function = ".$options[$brandNo]. "<br>"; 
//$brandAccess = $_POST['BrandDesc'];
$brandAccess = $options[$brandNo];
echo "submitted brand = ".$brandAccess. " <br> ";
}

$sql = "SELECT * from finished_goods WHERE BrandDesc LIKE '%$brandAccess%' "; 
echo "sql = ".$sql." <br>";
// get the result

谢谢,

0 个答案:

没有答案