设置在提交表单时将填充的空var

时间:2015-11-24 13:00:28

标签: php postgresql

我正在创建一个下拉框,它将过滤我的postgreSQL表,我需要创建一个空的var,如果表单已提交,将填充该空集,但我遇到了麻烦。

代码

<?php
$conn  = pg_connect("host=db.dcs.aber.ac.uk port=5432
                                        dbname=teaching user=csguest password=********");
// set empty var that will be populated if the form is submitted
$where = '';
if (isset($_POST['submit'])) {
    if (!empty($_POST['category'])) {
        //  I also need to build a where conditional, but that another question
        $where = " WHERE Category = '" . pg_escape_string($_POST['category']) . "'";
    }
}
$res = pg_query($conn, "SELECT Foodtype, Manufacturer, Description, Price 
                                        FROM food $where
                                        ORDER BY Category ASC");
echo "<table id=\"myTable\" border='1'>";
while ($a = pg_fetch_row($res)) {
    echo "<tr>";
    for ($j = 0; $j < pg_num_fields($res); $j++) {
         echo "<td>" . $a[$j] . "</td>";
    }
    echo "<td><form id='cart' name='cart' method='POST'  action='addToBasket.php'>
                                        <input type='submit' name='Select' id='Select' value='Add To Basket'>
                                        </form></td>";
    echo "</tr>\n";
}
echo "</table>\n";

$Alcoholic = pg_query("SELECT Foodtype, Manufacturer, 
                                    Description, Price FROM food WHERE      Category = 'Alcoholic'");


?> 

我在设置空变量时遇到问题。

0 个答案:

没有答案