I would be really grateful if someone can help me solve this. I just want the data to be displayed from the database, but this error keeps on happening.
The variable is Null, I have checked it using error reporting functions.
Fatal error: Uncaught TypeError: mysqli_query(): Argument #1 ($mysql) must be of type mysqli, null given in C:\xampp\htdocs\Train\index.php:100 Stack trace: #0 C:\xampp\htdocs\Train\index.php(100): mysqli_query(NULL, 'select * from t...') #1 {main} thrown in C:\xampp\htdocs\Train\index.php on line 100
This is the code:
<?php include("connection.php");?>
<!--Scheduler-->
        <div class="callout border-primary rounded-0 shadow">
            <fieldset>
                <section class="schedule">
                    <div class="container">
                        <legend>Find Schedule</legend>
                        <form>
                            <div class="row align-items-end">
                                <div class="col-md-3 col-sm-4">
                                    <label for="date">Desired Date</label>
                                    <br>
                                    <input type="date" id="date" value="<?//= $date ?>" required>
                                </div>
                                <div  class="col-md-3 col-sm-4">
                                    <label for="time">Desired Time</label>
                                    <br>
                                    <input type="time" id="time" value="<?//= $time?>" required>
                                </div>
                                <div  class="col-md-3 col-sm-4">
                                    <button class="btn btn-flat btn-primary" name="b1">Search</button>
                                </div>
                            </div>
                        </form>
                    </div>
            </fieldset>
        </div>
        <hr>
        <table>
            <colgroup>
                <col width="15%">
                <col width="15%">
                <col width="20%">
                <col width="20%">
                <col width="20%">
                <col width="10%">
            </colgroup>
            <thead>
                <tr class="bg-gradient-primary text-light">
                    <th>Train Number</th>
                    <th>Schedule</th>
                    <th>Train Name</th>
                    <th>Origin</th>
                    <th>Destination</th>
                    <th>class</th>
                    <th>Rate</th>
                    <th>Status</th>
                </tr>
            </thead>
            <!--php code to fetch data-->
                <?php
                global $con;
                $result=mysqli_query($con,"select * from train_schedule");
                while($row=mysqli_fetch_array($result))
                {
                ?>
                <tr>
                    <td><?php echo $row['train_no'];?></td>
                </tr>
                <tr>
                    <td><?php echo $row['date_schedule'];?></td>
                </tr>
                <tr>
                    <td><?php echo $row['train_name'];?></td>
                </tr>
                <tr>
                    <td><?php echo $row['origin'];?></td>
                </tr>
                <tr>
                    <td><?php echo $row['destination'];?></td>
                </tr>
                <tr>
                    <td><?php echo $row['class'];?></td>
                </tr>
                <tr>
                    <td><?php echo $row['price'];?></td>
                </tr>
                <tr>
                    <td><?php echo $row['status'];?></td>
                </tr>
                <?php 
                }
                ?>
                
        </table>
        </section>
    </body>
</html>
Additional suggestions on how to improve this code are also welcome because this I am a complete beginner at this.
This is the connection code:
<?php
            if(isset($_REQUEST['b1']))
                {
                    $con=mysqli_connect("localhost","root","","train");
                    if(!$con){
                    echo "not connect";
                    }
            }   
?>
I've tried several times and yes I have read through the other question already posted in here but the error still persists and I really have no idea on what to do here.
 
    