How to retrieve data from database and display specific column based on user input realtime using PHP?

  database, html, php, real-time

I’m making a web system for my school project which is vehicle reservation and this is probably my hardest point for me(and I hope the last.) I’m at this final situation which is to make a realtime price computation. I already make a table for vehicle and it’s price, each vehicle have different price based on their route assigned, and vehicle have also different types and price is also dependently.
Now I want my form reservation to have realtime display price based on user choices.

On my vehicle table which stored their price this is my field:

id | type | branch | route | price

And this is my reservation form that I want to have a realtime computation

<!DOCTYPE html>
<html>
<head>
    <title>Form</title>
</head>
<body>
<div>
    <?php
    include ('includes/connection.php');

    if(isset($_POST['btn-submit']))
    {
        //insert query is working propertly.
    }
    else
    {
        /*my idea here is to retrieve my price table when btn-submit is not click yet
        and store it on array*/
    }
    ?>
    <form action="submit-status.php" method="post">
        <label>Name</label>
        <input type="text" name="name">
        <label>Vehicle Type</label>
        <select id="type" name="tType">
            <option value=""></option>
            <option value="aircon">Aircondition</option>
            <option value="ordinary">Ordinary</option>
            <option value="pickup">Pickup</option>
        </select>
        <label>Branch</label>
        <input list="branch" name="from">
        <datalist id="branch">
            <option value=""></option>
            <option value="place1">Place 1</option>
            <option value="place2">Place 2</option>
            <option value="place3">Place 3</option>
        </datalist>
        <label>Route</label>
        <input list="route" name="dest">
        <datalist id="route">
            <option value=""></option>
            <option value="place1">Place 1</option>
            <option value="place2">Place 2</option>
            <option value="place3">Place 3</option>
        </datalist>

        <p>Price: <!--Display price here based on user input--></p>

        <input type="reset" name="Reset">
        <input type="submit" name="btn-submit" value="Submit">
    </form>
</div>
</body>
</html>

I hope someone can help me make this possible or introduce me a much nicer way.
Thankyou, Stay Safe Everyone and stay helpful.

Source: Ask PHP

LEAVE A COMMENT