0

Hello i am trying to get my form to say the corresponding price per day based upon the destination chosen on my drop down menu. It currently shows "Your base price is $50 per day" for all three of the destination options. I am new to php and setting up forms so forgive me if it is very off.

// html code

<div class="form-group">
<label> Travel Destination: </label>
<select name="travDest">
    <option value="Mexico">Mexico</option>
    <option value="Alaska">Alaska</option>
    <option value="Carribean">Carribean</option>
</select>
</div>


// php code

$travDest = $_GET["travDest"];

if ($_GET['travDest']) {
    echo "You will be traveling to 
".htmlspecialchars($_GET['travDest']);
}
else {
    return false;
}

if ($_GET["travDest"] = "Mexico") {
    echo "<br>Your base price is $50 per day";
}
else if ($_GET["travDest"] = "Alaska") {
    echo "<br>Your base price is $100 per day";
}
else if ($travDest = "Carribean") {
    echo "<br>Your base price is $75 per day";
}
else {
    return false;
}
Devin P
  • 3
  • 2

1 Answers1

1

Read the difference between = and ==.

In your if statements, you use single =, which means you are assigning $_GET["travDest"] to "Mexico". Since the assignment worked, it returned TRUE, so the if is satisfied and prints the 50$ per day price.

Switch to == in your if statements, you will see a huge difference!

Nic3500
  • 8,144
  • 10
  • 29
  • 40