Can someone help me with the following PHP/HTML coding in which I am getting the following error message.
"Warning: Undefined variable $result in C:\xampp\htdocs\view1.php on line 30
Fatal error: Uncaught TypeError: mysqli_fetch_assoc(): Argument #1 ($result) must be of type mysqli_result, null given in C:\xampp\htdocs\view1.php:30 Stack trace: #0 C:\xampp\htdocs\view1.php(30): mysqli_fetch_assoc(NULL) #1 {main} thrown in C:\xampp\htdocs\view1.php on line 30"
Below is the full coding of my page.
<? php
require_once("connection.php");
$query = " select * from student ";
$result = mysqli_query($conn,$query);
?>
<!DOCTYPE HTML>
<HTML>
    <style>
    table, th, td {
    border:1px solid black;
    }
    </style>
    <body>
        <h2>View Records</h2>
        <table style="width:100%">
        <tr>
        <td>Student ID</td>
        <td>First Name</td>
        <td>Surname</td>
        <td> Edit</td>
        <td> Delet</td>
        </tr>
        <?php
            while($row = mysqli_fetch_assoc($result))
                {
                    $StudentID = $row['student_ID'];
                    $FirstName = $row['first_name'];
                    $LastName = $row['last_name'];
                    
        ?>
            <tr>
                <td><?php echo $StudentID ?></td>
                <td><?php echo $FirstName ?></td>
                <td><?php echo $LastName ?></td>
                <td><a href="edit.php?GetID=<?php echo $StudentID ?>">Edit</a></td>
                <td><a href="delete.php?Del=<?php echo $StudentID ?>">Delete</a></td>
                </tr>
        <?php } ?>
        </table>
    </body>
</html>
All I am trying to do is get some data from my YAHUAS database table called Student as then I have some edit and delete PHP coding to work from here but have this error regarding the while($row = mysqli_fetch_assoc($result)) and can not find where the issue is.
At the top of the PHP command there is a link to another PHP called connection.php which has the following commands.
<?php
$servername = "localhost";
$username = "root";
$password = "Root";
$dbname = "Yahuas";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
}
?>
Thanks Adam
 
     
    