我的视图出勤表未从数据库中提取表

时间:2019-02-22 14:37:11

标签: php

当我尝试查看已经填写的出席者时,它会显示表格,但它是空的。我的SQL和Apache错误日志没有给出任何错误,就我而言,数据库表名称确实匹配。

这是我的“查看全部”的PHP代码。我还尝试在mysqli_query之前定义$ date = date(“ Y-m-d);并将” 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>

1 个答案:

答案 0 :(得分:1)

您没有引号,因此您的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