php - 注意:尝试在第 97 行名称的 C:\xampp\htdocs\res\index.php 中访问 null 类型值的数组偏移量:
问题描述
我已经创建了学生成绩门户。如果卷号和出生日期与数据库中的数据匹配,则必须显示学生的姓名和分数。成功显示学生的分数详情。但显示学生姓名时显示错误。下面是错误。我现在该怎么办?
注意:尝试访问第 97 行 C:\xampp\htdocs\res\index.php 中 null 类型值的数组偏移量
姓名:
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>";
}
?>
请帮我解决这个问题。
解决方案
那是因为 if 语句没有运行,name 没有任何值,所以它抵消了 NULL
推荐阅读
- mysql - 如何使用 SQL 将小时范围转换为总小时数?
- python - 我可以使用正则表达式仅提取标题吗?
- node.js - 对于2核机器,用pm2设置4个进程会有所帮助吗?
- php - 循环遍历PHP中的json解码数组
- javascript - 是否有适用于类组件的 React Material-UI makeStyles() 函数的非挂钩替代方案
- html - 为什么不显示:阻止元素集空间像其他元素一样被保留?
- java - 如何让bazel在java中通过maven_jar递归下载依赖项
- excel-formula - 我需要在公式输出范围内自动计算 UNIQUE 值,该范围可能为空白,也可能不为空白
- r - 如何在数据帧列表(或子集数据帧)上循环地理映射函数
- node.js - 使用 node.js 从 2 个 postgres 表中查询所有数据