Skip to content
Advertisement

Notice: Trying to access array offset on value of type null in C:xampphtdocsresindex.php on line 97 name:

I’ve created student result portal. It must display the student’s name and marks if the roll number and date of birth matches the data on database. Successfully, it displays the student’s mark details. But it shows error when displaying the student’s name. Below is the error. what I’ve to do now?

Notice: Trying to access array offset on value of type null in C:xampphtdocsresindex.php on line 97

name:

php

<?php
 include('header.php')
  ?>
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-12 jumbotron">
                        <h2 style="text-align: center;">                                
Sri Meenakshi Government College for Women                                 
                        </h2>                            
                </div>
            </div>
        </div>

        <div class="student-info text-center">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12 jumbotron">
                        
                        <form action="index.php" method="post">
                        <input type="text" name="sname" placeholder="Your Full Name" style="width: 240px;height: 35px;">
            <input type="text" name="roll" placeholder="Your Register Number" style="width: 240px;height: 35px;">
            <input type="text" name="birth" placeholder="mm/dd/yyyy" style="width: 240px;height: 35px;">
              <input type="submit" name="show" value="Show Result" class="btn btn-success text-center" style="margin-left: -100px;" >  
              <center><button onclick="window.print()" class="btn">Save</button>
                        <style>
                        .btn{
                            width:250px;
                            float:right;
                        }
                        </style>
                        </form>                            
                    </div>
                </div>
            </div>
        </div>
<table class="table table-striped table-bordered table-responsive text-center">
<tr >
    <th class="text-center">Subject</th>
    <th class="text-center">Internal Mark</th>
    <th class="text-center">External Mark</th>
    <th class="text-center">Total</th>
    <th class="text-center">Result</th>
</tr>
<?php 
include('dbcon.php');
if (isset($_POST['show'])) {
                        //echo "<center>"."Name:" .$_POST['sname']."<br>";
                        //echo "Register Number:" .$_POST['roll']."<br>";                        
                        $dateofbirth = $_POST['birth'];
                        $RollNo = $_POST['roll'];
                        $sql = "SELECT * FROM `student` WHERE `birth` = '$dateofbirth' AND `rollno`='$RollNo'";
    $result = mysqli_query($conn,$sql);
    if (mysqli_num_rows($result)>0) {
        while ($DataRows = mysqli_fetch_assoc($result)) {
            $Id = $DataRows['id'];
            $RollNo = $DataRows['rollno'];
            $Name = $DataRows['name'];
            $sub = $DataRows['subject'];
            $intm = $DataRows['intmark'];
            $extmark = $DataRows['extmark'];
            $tot = $DataRows['total'];
            $res = $DataRows['result'];
            ?>
            <tr>
                <td><?php echo $sub; ?></td>
                <td><?php echo $intm; ?></td>
                <td><?php echo $extmark; ?></td>
                <td><?php echo $tot; ?></td>
                <td><?php echo $res; ?></td>
            </tr>
            <?php
        }
        
    } else {
        echo "<tr><td colspan ='7' class='text-center'>No Record Found</td></tr>";
    }
   echo "name:".$DataRows['name']."<br>";
 }
 ?>

here is my database entries

Please help me to solve this.

Advertisement

Answer

That is because the if statement doesnt get run through, name does not have any value in it so it offsets NULL

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement