PHP isset post 条件不执行

PHP isset post condition doesn't execute

我有一个使用 post 方法提交更改的表单,我认为我没有很好地使用 isset 函数,因为提交时我的页面上没有任何更改,我应该在我的页面上显示产品页。

这是我的表格:

<form method="post" style="margin-left:5px; margin-right: 5px; margin-bottom: 10px;" name="myform">
  <select size="1" onblur="this.size = 1" onchange="myform.submit();" class="form-control" id="filterText">
    <option selected value="">Cat  gories</option>
    <option name="sofa" value="sofa">Canap  s</option>
    <option name="bed" value="bed">Lits</option>
  </select>
</form>

这是同一个文件中表格后面的 isset 条件 :

if(isset($_POST["sofa"])){
    $url="https://sik.search.blue.cdtapps.com/fr/fr/product-list-page/more-products?sessionId=22037cc5-f73c-4f71-a1d4-a90285da1789&category=fu003&sort=RELEVANCE&start=0&end=275&c=lf&v=20201118";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    $result = curl_exec($ch);
    $products = json_decode($result, true);
    curl_close($ch);
    echo '<div id="wrap" class="wrap">';

     foreach ($products['moreProducts']['productWindow'] as $items)
     {
        echo '<div class="bed_images" id="bed">';
        echo '<img data-enlargeable class="images" src=' . $items['mainImageUrl'] . '?f=xxs'  . '/>';
        echo '<h2 class="img_title">' . $items['name'] . '</h2>';
        echo '<p class="img_price">' . $items['priceNumeral'] . ' ^b ' . '</p>';
        echo '<p class="img_description">' . $items['typeName'] . '</p>';
        echo '</div>';
     }
     echo '</div>';

} elseif (isset($_POST["bed"])){
    $url="https://sik.search.blue.cdtapps.com/fr/fr/product-list-page/more-products?sessionId=22037cc5-f73c-4f71-a1d4-a90285da1789&category=bm003&sort=RELEVANCE&start=0&end=275&c=lf&v=20201118";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    $result = curl_exec($ch);
    $products = json_decode($result, true);
    curl_close($ch);
    echo '<div id="wrap" class="wrap">';
     foreach ($products['moreProducts']['productWindow'] as $items)
     {
        echo '<div class="bed_images" id="bed">';
        echo '<img data-enlargeable class="images" src=' . $items['mainImageUrl'] . '?f=xxs'  . '/>';
        echo '<h2 class="img_title">' . $items['name'] . '</h2>';
        echo '<p class="img_price">' . $items['priceNumeral'] . ' ^b ' . '</p>';
        echo '<p class="img_description">' . $items['typeName'] . '</p>';
        echo '</div>';
     }
     echo '</div>';
} else {
    $url="https://sik.search.blue.cdtapps.com/fr/fr/product-list-page/more-products?sessionId=22037cc5-f73c-4f71-a1d4-a90285da1789&category=fu001&sort=RELEVANCE&start=0&end=275&c=lf&v=20201118";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    $result = curl_exec($ch);
    $products = json_decode($result, true);
    curl_close($ch);
    echo '<div id="wrap" class="wrap">';

     foreach ($products['moreProducts']['productWindow'] as $items)
     {
        echo '<div class="bed_images" id="bed">';
        echo '<img data-enlargeable class="images" src=' . $items['mainImageUrl'] . '?f=xxs'  . '/>';
        echo '<h2 class="img_title">' . $items['name'] . '</h2>';
        echo '<p class="img_price">' . $items['priceNumeral'] . ' ^b ' . '</p>';
        echo '<p class="img_description">' . $items['typeName'] . '</p>';
        echo '</div>';
     }
     echo '</div>';
}
?>

else 条件得到验证,因为我的页面上一直显示最后的 url 产品(在提交表单之前和之后)所以我的问题是我认为我对 isset 的误解条件。

<option> tag doesn't include the name attribute.

您必须命名您的 <select> 标签并使用其值:

<form method="post" style="margin-left:5px; margin-right: 5px; margin-bottom: 10px;" name="myform">
  <!--    v--------------v----- Check this -->
  <select name="furniture" size="1" onblur="this.size = 1" onchange="myform.submit();" class="form-control" id="filterText">
    <option selected value="">Cat  gories</option>
    <option value="sofa">Canap  s</option>
    <option value="bed">Lits</option>
  </select>
</form>
if(isset($_POST["furniture"]))
{
    if ($_POST["furniture"] === "sofa")
    {
        // your code for sofa
    }
}