0

i have combobox code like this

<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">

and in file named "plot.php" like this

<?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");
  }
?>

all i want is when i pick one of the item in my combobox, it will be the parameter for the other page to open after i click "plot" button. for the example, when i pick NO2, maps_no2.php will show. when i try that code above, it just work on the first condition, although i pick so2. how can i solve this? anyone?? please.

Berriel
  • 12,659
  • 4
  • 43
  • 67
kenry
  • 7
  • 4

3 Answers3

1

Here is your problem:

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

Should be

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

If you just use the single =, it SETS the variable to that value. Then it will always be true.

durbnpoisn
  • 4,666
  • 2
  • 16
  • 30
1

You have to compare, in your statements you are assigning instead:

<?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");
  }
?>
taxicala
  • 21,408
  • 7
  • 37
  • 66
0

You should use == for comparisons

<?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");
  }
?>
Berriel
  • 12,659
  • 4
  • 43
  • 67