I'm writing you since I have been told that the code written below is unsecured because I can be hacked through SQL Injection.
I have tried to read some guides related to the "prepared statement" topic but I did not manage to solve the issue.
Can you please help me out? I would like to understand and solve my issue.
Thank you in advance to everyone wishing to help.
<html>
<body>
<form action='index.php' method='post'>
<h2>Select Departure:</h2>
<select name="departures" class="form-control">
        <option value="">--- Select Departure ---</option>
                    <?php
                        require('prova1.php');
                        $sql1 = "SELECT * FROM departures"; 
                        $sql2 = "SELECT * FROM arrivals"; 
                        $result1 = $mysqli->query($sql1);
                        while($row1 = $result1->fetch_assoc()){
                    ?>   
                    <option value="<?php echo $row1["dep_name"]; ?>"><?php echo $row1["dep_name"]; ?></option>
                    <?php } ?>
</select>
<br>
<h2>Select Arrival:</h2>
<select name="arrivals" class="form-control">
        <option value="">--- Select Arrival ---</option>
                    <?php
                        $result2 = $mysqli->query($sql2);
                        while($row2 = $result2->fetch_assoc()){
                    ?>   
                    <option value="<?php echo $row2["arr_name"]; ?>"><?php echo $row2["arr_name"]; ?></option>
                    <?php } ?>
</select>
<br>
<h2>Select # of passengers</h2>
<select name="passengers" class="form-control">
        <option value="">--- # of passengers ---</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
</select>
<br>
<h2>Select # of bags</h2>
<select name="bags" class="form-control">
        <option value="">--- # of bags ---</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
</select>
<br>
<input type='submit' name='submit' id='submit' value='Get Selected Values' />
</form>
<?php
    if(isset($_POST['submit'])){
    $selected_val1 = $_POST['departures'];  
    $selected_val2 = $_POST['arrivals'];
    $selected_val3 = $_POST['passengers'];
    $selected_val4 = $_POST['bags'];    
    if ($selected_val3 < 4 AND $selected_val4 < 4){
    echo "You will drive with a taxi!"; 
    $query3 = "SELECT * FROM taxilist WHERE dep_name = '".$selected_val1."' AND arr_name = '".$selected_val2."'";
    } else {
    echo "You will drive with a van!";
    $query3 = "SELECT * FROM vanlist WHERE dep_name = '".$selected_val1."' AND arr_name = '".$selected_val2."'";
    }
    require('prova1.php');
    echo "<br>The price from " .$selected_val1. " to " .$selected_val2. " is: ";
    $result3 = $mysqli->query($query3);
        while($row3 = $result3->fetch_assoc()){
        echo $row3['price'];
        }
    }
?>
</body>
</html>
 
     
     
    