jeudi 21 septembre 2017

PHP Post form, not giving any response. (Travel calculator)

I'm making a traving calculator that calulates the price for traveling between 2 places.

But when i click the Calculate button, it leaves me with a blank space, everything in the "if(isset($_post..." is not working,

Does anyone have any idea what i'm doing wrong, cause i struggled for 3 hours, but still can't find it...

Travel.php

    <h4>Travel Price Calculator</h4>

<form action="travel.php" methode="post">
     Departure:
    <select name="departure" value="true">
        <option value=" ">Departure:</option>
        <option value="1">Amsterdam</option>
        <option value="2">Utrecht</option>
        <option value="3">Den Haag</option>
        <option value="4">Rotterdam</option>
    </select>
     Arrival:
    <select name="arrival" value="true">
        <option value=" ">Arrival:</option>
        <option value="1">Amsterdam</option>
        <option value="2">Utrecht</option>
        <option value="3">Den Haag</option>
        <option value="4">Rotterdam</option>
    </select><br><br>
    <input type="submit" name="submit" value="Calculate">
</form>
<hr>
<?php
    include "calculator.php";
?>

Calculator.php

    <?php
if(isset($_POST["submit"]) ){
        $d = $_POST["departure"];
        $a = $_POST["arrival"];
        echo $d;
        echo $a;
function travelprice($departure, $arrival) {
    $travelprice = array();
    $travelprice[1] = array();
    $travelprice[2] = array();
    $travelprice[3] = array();
    $travelprice[4] = array();
    $travelprice[1][1] = 0;
    $travelprice[1][2] = 30;
    $travelprice[1][3] = 60;
    $travelprice[1][4] = 90;
    $travelprice[2][1] = 30;
    $travelprice[2][2] = 0;
    $travelprice[2][3] = 40;
    $travelprice[2][4] = 20;
    $travelprice[3][1] = 60;
    $travelprice[3][2] = 40;
    $travelprice[3][3] = 0;
    $travelprice[3][4] = 10;
    $travelprice[4][1] = 90;
    $travelprice[4][2] = 20;
    $travelprice[4][3] = 10;
    $travelprice[4][4] = 0;

    echo $travelprice[$departure][$arrival];

//    $reis = json_encode($travelprice);
//    file_put_contents('data.json', $reis);
}
travelprice($d,$a);
    }
?>

And here is my result when i press Calculate

(Remember when i echo something in the calculator outside the if statement, it shows.)

The result:

enter image description here

Thanks for the help already =)

Aucun commentaire:

Enregistrer un commentaire