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

Asked

Viewed 787 times

0

I have to make a form in PHP that calculates the distance, speed and time that a person makes during a journey and tell how many liters were used, but I’m struggling to make 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>

  • What’s the problem ? Apparently you’re sending by GET for calculadora.php, then need to calculate in this file or do via JS,JQUERY, etc.

  • Your question doesn’t make much sense. You want to calculate "what?" if your form already asks all rss

2 answers

1

Actually, we’re 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.

  • Implies that the consumption was informed in the question on this line $l= $l= $d/12; being 12

  • So come on: What exactly is missing? Do you want to show the result on the screen? Want to write to the database? Want to show the calculation without refreshing the screen? Want to fill in the <input name="num4" type="text" /> with the calculation result? Pre for example, see https://jsfiddle.net/L4muax9t/25for example/

-1

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

In case you send the data via GET and Google returns aJSON with all data, it is easier using JS, but it is also possible to use PHP

Browser other questions tagged

You are not signed in. Login or sign up in order to post.