根据组合框的选择打开新页面,然后单击按钮


open new page based on combobox choice and click button

我有这样的组合框代码

<form action="plot.php" method="POST">
    <select name="variabel">
        <option value="no2">NO2</option>
        <option value="so2">SO2</option>
        <option value="ozone">ozone</option>
        <option value="aerosol">aerosol</option>
    </select>
    <input type="submit" value="plot" style="width:500px;height:48px">

和在名为"plot.php"的文件中像这样

<?php
  $variabel = $_POST['variabel'];
  if ($variabel = "no2") {
    header("location:maps_no2.php");
  } else if ($variabel = "so2") {
    header("location:maps_so2.php");
  } else if ($variabel = "ozone") {
    header("location:maps_ozone.php");
  } else {
    header("location:maps_aerosol.php");
  }
?>

所有我想要的是,当我选择一个项目在我的组合框,它将是参数的另一个页面打开后,我点击"plot"按钮。例如,当我选择NO2时,将显示maps_no2.php。当我尝试上面的代码时,它只适用于第一个条件,尽管我选择了so2。我怎么解决这个问题?有人知道吗? ?请。

你必须比较,在你的语句中你正在分配:

<?php
  $variabel = $_POST['variabel'];
  if ($variabel == "no2") {
  header("location:maps_no2.php");
  }
  else if ($variabel == "so2")
  {
  header("location:maps_so2.php");
  }
  else if ($variabel == "ozone")
  {
  header("location:maps_ozone.php");
  }
  else 
  {
  header("location:maps_aerosol.php");
  }
?>

你的问题是:

<?php
 if $variabel = $_POST['variabel'];

应该是

<?php
  if $variabel == $_POST['variabel'];

如果您只使用单个=,它将变量设置为该值。

您应该使用==进行比较

<?php
  $variabel = $_POST['variabel'];
  if ($variabel == "no2") {
    header("location:maps_no2.php");
  } else if ($variabel == "so2") {
    header("location:maps_so2.php");
  } else if ($variabel == "ozone") {
    header("location:maps_ozone.php");
  } else {
    header("location:maps_aerosol.php");
  }
?>