php - 我的视图考勤表没有从数据库中提取表
问题描述
当我尝试查看已填满的出勤时,它会调出表格,但它是空的。我的 SQL 和 Apache 错误日志没有给出任何错误,就我而言,数据库表名确实匹配。
这是我的查看全部的 PHP 代码。我也尝试在 mysqli_query 之前定义 $date=date("Ymd); 并将 "where date=$_POST[date]" 更改为 "date=$date" 但无济于事
<?php
include("includes/dbhA.inc.php");
include("includes/PresenceRoster.inc.php");
?>
<div class="panel panel-default">
<div class="panel panel-heading">
<h2>
<a class="btn btn-success" href="Add.php"> Add Students </a>
<a class="btn btn-info pull-right" href="AttendanceTable.php"> Back </a>
</h2>
<div class="panel panel-body">
<form action="AttendanceTable.php" method="post">
<table class="table table-striped">
<tr>
<th>#serial Number</th> <th>Student Name</th> <th>Roll Numbers</th> <th>Attendance Status</th>
</tr>
<?php
$result=mysqli_query($con, "select * from attendance_records where date=$_POST[date]");
$serialnumber=0;
$counter=0;
while($row=mysqli_fetch_array($result))
{
$serialnumber++;
?>
<tr>
<td> <?php echo $serialnumber; ?> </td>
<td> <?php echo $row['student_name']; ?>
</td>
<td> <?php echo $row['roll_number']; ?> </td>
<td>
<input type="radio" name="attendance_status[<?php echo $counter; ?>]" value="Present"> Present
<input type="radio" name="attendance_status[<?php echo $counter; ?>]" value="Absent"> Absent
</td>
</tr>
<?php
$counter++;
}
?>
</table>
<input type="submit" name="submit" value="Submit" class="btn btn-primary">
</form>
</div>
</div>
这是我查看考勤前页面的 PHP 代码
<?php
include("includes/dbhA.inc.php");
include("includes/PresenceRoster.inc.php");
?>
<div class="panel panel-default">
<div class="panel panel-heading">
<h2>
<a class="btn btn-success" href="Add.php"> Add Students </a>
<a class="btn btn-info pull-right" href="AttendanceTable.php"> Back </a>
</h2>
<div class="panel panel-body">
<table class="table table-striped">
<tr>
<th>Serial Number</th> <th>Dates</th> <th>Show Attendance</th>
</tr>
<?php
$result=mysqli_query($con, "SELECT distinct date FROM attendance_records");
$serialnumber=0;
while($row=mysqli_fetch_array($result))
{
$serialnumber++;
?>
<tr>
<td> <?php echo $serialnumber; ?> </td>
<td> <?php echo $row['date']; ?> </td>
<td>
<form action="show_attendance.php" method="POST">
<input type="hidden" value="<?php echo $row['date'] ?>" name="date">
<input type="submit" value="Show Attendance" class="btn btn-primary">
</form>
</td>
</tr>
<?php
}
?>
</table>
<input type="submit" name="submit" value="Submit" class="btn btn-primary">
</form>
</div>
</div>
解决方案
你没有任何引号,所以你的 WHERE 条件
where date=$_POST[date]
扩展为where date=2019-02-17
。MySQL 愉快地计算 2019 - 2 - 17 = 2000。没有日期匹配,所以你得到零记录。
您应该对采用此类参数的查询使用准备好的语句,这样数据库就会添加必要的引号和转义序列http://php.net/manual/en/mysqli.quickstart.prepared-statements.php
推荐阅读
- python - bmi 计算器如何重新启动计算器以返回顶部的是/否
- java - Spring Boot 2.3 数据源注入
- php - TYPO3 v10 如何在 FrontEnd 中获取对象的 crdate 或 tstamp
- excel - 使用格式和布局将多个表从 Access DB 导出到 Excel 工作簿
- django - NoReverseMatch 与 unittest
- vue.js - 如何使用路由器链接自定义导航而不是`to`道具
- vuejs2 - 如何在 vue/cli 4 应用程序的 cypress 中使用混合?
- vba - 保存类模块后解决一次访问中的写入冲突错误
- python - Matplotlib 对数图,set_xlim
- javascript - 自定义反应钩子不更新它的价值