从循环中取出正确的价值

Below you can see my code. No need to show the other parts or the database table.

Code

    <form method="POST" action="custInfo.php">
<center><input type="submit" id="btn" name="room"></center>
$query = mysqli_query($conn, "SELECT room_name, room_type, room_rate, inclusive, description, room_status, max_cap
                                    FROM room
                                    WHERE room_status = 'available'");


if(mysqli_num_rows($query)){
    while($row = mysqli_fetch_assoc($query)){
        echo "<div class='chooseRoom'>";
        echo "<div class='indent'>";
        echo "<h4>".$row['room_type']."</h4>
            <h5>".$row['room_rate']."php</h5>";
        echo "<img src='../images/".$row['room_type'].".jpg' width=250 height=160>";
        echo "<h5>Number of Adult&nbsp;";
        echo "<select name='adult'>";
        $x = 0;
        while($x <= $row['max_cap']){
        echo "<option>";
        echo $x;
        echo "</option>";
        $x++;
        }
        echo "</select>";
        echo "&nbsp;&nbsp;&nbsp;Number of Children&nbsp;";
        echo "<select name='children'>";
        echo "<option>0</option>";
        echo "<option>1</option>";
        echo "<option>2</option>";
        echo "<option>3</option>";
        echo "<option>4</option>";
        echo "<option>5</option>";
        echo "</select></h5>";
        echo "<table class='table'>";
        echo "<thead>";
        echo "<th>Inclusive</th><th>Description</th>";
        echo "</thead>";
        echo "<tbody>";
        echo "<td>".$row['inclusive']."</td><td>".$row['description']."</td>";
        echo "</tbody>";
        echo "<tfoot>";
        echo "<td colspan='2'>";
        echo $row['room_status'];
        echo "</td>";
        echo "</tfoot>";
        echo "</table>";
        echo "</div>";
        echo "</div>";
    }
}
else{
    echo "No rooms available in the date you desire!";
}
        </form>

I need to take the value from the correct input. This code always takes the last input from the loop. And I have been trying to research about this for a day now. How do I fix this?

Please follow the below code:

$result = mysqli_query($connection, $query);

?>
<form method="POST" action="custInfo.php">
    <center><input type="submit" id="submit_button" name="room_submit" value="Submit"></center>
    <?php
    while ($row = mysqli_fetch_assoc($result)) {
        ?>
    <div class='chooseRoom'>
        <div class='indent'>
            <h4><?php echo $row['room_type']; ?></h4>
            <h5><?php echo $row['room_rate']; ?></h5>
            <img src='../images/<?php echo $row['room_type']; ?>.jpg' width="250" height="160">
            <h5>Number of Adult&nbsp;
                <select name='adult[]'> <!-- NOTICE HERE... -->
                    <?php
                    $x = 0;
                    while($x <= $row['max_cap']){
                        ?>
                    <option><?php echo $x; ?></option>
                        <?php
                        $x++;
                    }
                    ?>
                </select>
                &nbsp;&nbsp;&nbsp;Number of Children&nbsp;

                <select name='children[]'>  <!-- NOTICE HERE... -->
                    <option>0</option>
                    <option>1</option>
                    <option>2</option>
                    <option>3</option>
                    <option>4</option>
                    <option>5</option>
                </select>
            </h5>
            <table class='table'>
                <thead>
                    <th>Inclusive</th>
                    <th>Description</th>
                </thead>
                <tbody>
                    <td><?php echo $row['inclusive']; ?></td>
                    <td><?php echo $row['description']; ?></td>
                </tbody>
                <tfoot>
                    <td colspan='2'><?php echo $row['room_status']; ?></td>
                </tfoot>
            </table>
        </div>
    </div>
        <?php
    }
    ?>
</form>

In the above code you will see that we are looping through some DB Rows. So there will be multiple Adult and Children selects. So for that case we are making them arrays with [] at the end. Which will preserve all inputs with same name inside an array.

/**
 * After form submittion look at $_POST variable... eg.
 *
 * echo "<pre>";
 * print_r($_POST);
 * echo "</pre>";
 */

/**
 * 
 * The $_POST['adult'] and $_POST['children'] will be an array. 
 * And then you can have whichever value you want by calling the right Index.
 *
 * Otherwise you can loop through them:
 * foreach ($_POST['adult'] as $key => $value) {
 *      echo $value;
 * }
 * And ---- for children.
 * foreach ($_POST['children'] as $key => $value) {
 *      echo $value;
 * }
 * 
 */

Because of the names of inputs is duplicate. Try to change name of the input to Array. For example:

<select name='children[]'></select>