0

I am trying to insert into a database the current rate multiplied by the mileage with an if statement. I need the mileage to be doubled if the journey is a return journey.

Tried some code which is posted below but struggling to make it work as it just takes the else line of code without considering if its no a return.

returntrip is posted from a form with the value of Y for yes, N for no. I want amount to equal multiply the rate which is posted from the form by the mileage but the mileage could be exact as entered on the form if not a return journey or multiplied if a return journey.

 $tripis = $returntrip;
 if ($tripis="Y"){
     $checkmiles = $mileage * 2;
 } else { 
     $checkmiles = $mileage;
 }

 $amount = $rate * $checkmiles;

The above code just inserts the else regardless if the returntrip value is Y or N.

Jeemusu
  • 10,415
  • 3
  • 42
  • 64

1 Answers1

1

In your if statement you are using a single equals operator =, which is assigning the string "Y" to the $tripis variable. To make a comparison between two values you need to use two equal symbols ==.

$tripis = $returntrip;

if ($tripis == "Y"){
    $checkmiles = $mileage * 2;
}else { 
    $checkmiles = $mileage;
}

$amount = $rate * $checkmiles;
Jeemusu
  • 10,415
  • 3
  • 42
  • 64