首页 > 解决方案 > 我的视图考勤表没有从数据库中提取表

问题描述

当我尝试查看已填满的出勤时,它会调出表格,但它是空的。我的 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>

标签: php

解决方案


你没有任何引号,所以你的 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


推荐阅读