I have to make a form in PHP that the cost and time of a car trip

0

I have to make a PHP form that calculates the distance, speed, and time a person does during a course and say how many liters were used, but I'm having trouble making sense of the form.

              Calculation                       

    <form action=calculadora.php" method="get" />

        <p> Distancia :      <input name="num1" type="text" /> </p> 
        <p> Tempo :          <input name="num2" type="text" /> </p> 
        <p> Velocidade :  <input name="num3" type="text" />  </p>
        <p> Litros Usados :  <input name="num4" type="text" />  </p>
        <input type="submit" value="Calcular" />     

</form> 
<?php

$num1=$_GET['num1'];
$num2=$_GET['num2'];
$num3=$_GET['num3'];
$num4=$_GET['num4'];

    //Aqui ira o calculo dos valores Num1 Num2 Num3

$d= $num2*$num3; //d= Distancia
$l= $d/12;       //l- Litros Usados



?>      
</body>

    
asked by anonymous 14.11.2017 / 12:01

2 answers

1

There are actually missing parameters. If you want to know the amount of liters used, you need to have a parameter of how many KM the vehicle makes per liter.

Ex:

$num1 = 418; //distancia percorrida de 418 km
$consumo_medio = 8; //o consumo do veiculo
$consumo_realizado = $num1 / $consumo_medio; //distancia dividida pelo consumo médio.

The value of the variable $consumo_realizado will be 52.25 Liters.

    
14.11.2017 / 13:04
-1

You can use google maps api , through which you can give the point of origin, destination and mode (car, walk, bus ...) and the maps te of the distance time among other things, it is also possible to show the route in html

In case you send the data via GET and Google returns a JSON with all data, it is easier using JS, but you can also use PHP

    
14.11.2017 / 12:43