将此问题解决了三天以上。
我正在创建一个允许用户搜索某些条件的表单。
为什么使用get方法时公司和类别的值没有传递给网址?
<form class="main-searchbox-container" role="search" method="get" action="search-results.php">
<div class="form-group" id="main-searchbox">
<input id="target" type="text" class="form-control main-search-input" placeholder="Search..." name="target" value="<?php if (isset($_POST['target'])) echo $_POST['target']; ?>" />
</div>
<div class="selection-container">
<select name="company" class="header-selection" form="main-searchbox">
<option value="company" name="company">Company</option>
</select>
</div>
<div class="selection-container">
<select name="category" class="header-selection" form="main-searchbox">
<?php
// Make the query:
$sql = "select Business_Category from business_categories order by Business_Category ASC";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while ($row = mysqli_fetch_assoc($result)) {
echo '<option value="'.$row['Business_Category'].'" name="'.$row['Business_Category'].'">'.$row['Business_Category'].'</option>';
}
} else { echo "----";} // End
?>
</select>
</div>
<input id="submit" class="btn btn-default main-search-button" type="submit" name="submit" value="Search">
</form>
解决此问题必须非常简单,并且您的反馈可以更轻松地解决这个问题。
感谢您的时间。
答案 0 :(得分:0)
通过删除两个form="main-searchbox"
元素(<select>
中)中的<div class="selection-container">
来起作用,因为<form>
上没有与该名称匹配的ID,例如{ {3}}在评论中说。
请参见工作代码:
<form class="main-searchbox-container" role="search" method="get" action="search-results.php">
<div class="form-group" id="main-searchbox">
<input id="target" type="text" class="form-control main-search-input" placeholder="Search..." name="target" value="<?php if (isset($_POST['target'])) echo $_POST['target']; ?>" />
</div>
<div class="selection-container">
<select name="company" class="header-selection">
<option value="company" name="company">Company</option>
</select>
</div>
<div class="selection-container">
<select name="category" class="header-selection">
<?php
// Make the query:
$sql = "select Business_Category from business_categories order by Business_Category ASC";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while ($row = mysqli_fetch_assoc($result)) {
echo '<option value="'.$row['Business_Category'].'" name="'.$row['Business_Category'].'">'.$row['Business_Category'].'</option>';
}
} else { echo "----";} // End
?>
</select>
</div>
<input id="submit" class="btn btn-default main-search-button" type="submit" name="submit" value="Search">
</form>