-2

我正在尝试在 PHP 中创建一个表单,然后将变量传递到下一页。我的问题是表单中的下拉元素根本没有传递它们的值。当我在下一页上执行 print_r($_GET) 以查看通过表单传递了哪些值时,只会出现类型为“text”或“radio”的输入。我不确定我做错了什么,因为我过去已经让这个工作了。有人能帮我吗?我知道我从 MySQL 查询中提取的变量名称是正确的,ID 也是正确的。

//begin form    
print "<form action = 'restaurant_confirm.php' method = 'GET'>";
print "Restaurant Name: <input type = 'text' size = 50 name = restaurant_name></br>";
// drop down for cuisine
print "Cuisine: <select>";
    while ($row = mysql_fetch_array($cuisine_result) ){
        print "<option name = 'cuisine' value = '".$row['cuisine_id']."'>". $row['cuisine_name']. "</option>";
    }
print "</select></br>";
// drop down form restaurant type
print "Restaurant Type: <select>";
    while ($row = mysql_fetch_array($type_result) ){
        print "<option name = 'restaurant_type' value = '".$row['type_id']."'>";
        print $row['restaurant_type'];
        print "</option>";
    }
print "</select></br>";
//Check boxes for price point
//table for alignment
print "Select one price point </br>";
print "<table>";
    //header row
    print "<tr>";
    print "<td>Price Point</td>";
    print "<td>Value</td>";
    print "<td>Select</td>";
    print "</tr>";
    while ($row = mysql_fetch_array($price_result)) {
        print "<tr>";
        //prints the price point
        print "<td>";
        print $row['price_point'];
        print "</td>";
        //prints the value
        print "<td>";
        print $row['price_value'];
        print "</td>";
        print "<td>";
        // radio button to choose
        print "<input type = 'radio' name = 'price_selection' value = ".$row['price_id'].">";
        print "</tr>";
    }

print"</table></br>";

//Check boxes for gluten type
//table for alignment
print "Select one gluten type</br>";
print "<table>";
    //header row
    print "<tr>";
    print "<td>Gluten Type</td>";
    print "<td>Select</td>";
    print "</tr>";
    while ($row = mysql_fetch_array($gluten_result)) {
        print "<tr>";
        //prints the gluten type
        print "<td>";
        print $row['gluten_type'];
        print "</td>";
        print "<td>";
        // radio button to choose
        print "<input type = 'radio' name = 'gluten_selection' value = ".$row['gluten_type_id'].">";
        print"</td>";
        print "</tr>";
    }

print "</table></br>";
//submit button
print "<input type = 'submit' value = 'Add'>";

打印 ””;

4

2 回答 2

2

select没有名字,这是必需的。

将选择更改为<select name="whatever">,您将能够通过$_GET["whatever"]下一页获取它们。

于 2012-11-28T21:03:52.987 回答
0

您的输入和选择字段没有name指定参数。name定义变量名。

<input name="blah" />也会如此$_GET['blah']

于 2012-11-28T21:03:45.557 回答