I'm working on a little work on conversion but in reality I'm learning the switch case statement in PHP =D
When I select my country, I can applicate the good rate.
Here is the HTML
<select class="form-control" name="devise">
<option name="pays" value="USA">USA</option>
<option name="pays" value="EUR">EUR</option>
<option name="pays" value="JPY">JPY</option>
</select>
Here is the PHP
if (isset($_POST['conversion'])){
if(!is_numeric($_POST['montant'])){
echo('<div class="alert alert-danger style="display:none;">veuillez insérer un nombre</div>');
exit();
} else if(isset($_POST['pays'])){
$devise = $_POST['devise'];
$montant = $_POST['montant'];
switch($pays){
case 'USA':
$resultConvert = $montant * 1.3;
echo('<div class="alert alert-success" style="display:none; role="alert">dollar</div>');
break;
case 'EUR':
$resultConvert = $montant * 1.2;
echo('<div class="alert alert-success" style="display:none; role="alert">euro</div>');
break;
case 'JPY':
$resultConvert = $montant * 1.5;
echo('<div class="alert alert-success" style="display:none; role="alert">yen</div>');
break;
default:
echo('<div class="alert alert-danger style="display:none;">Veuillez choisir une devise</div>');
}
return $resultConvert;
}
} I wanted to return $resultConvert, but I don't have errors from the server. I tried to var_dump() it, but It displays nothing.
Thank you for your help. I want to learn where I did a mistake.
P.S. The rates of convertion are wrong, I just want to display the good result with the good device.