繁体   English   中英

我的SQL查询有什么问题? 它不存储数据

[英]What is wrong with my sql query? It doesnt store the data

请帮助我与我的SQL查询 我无法在数据库中存储复选框的值和日期 有什么解决办法吗? 如果没有的话。 我应该改变什么? 关于sql和php,我只是一个初学者。 预先谢谢

<form method = "POST"><strong>
Set the date: 
</strong>
<input type = "date" name = "set_date"></br></br>


<table width="600" border="1" cellpadding="1" cellspacing="1">
<tr>

<th>First name</th>
<th>Last name</th>
<th>Subject</th>
<th>Section</th>
<th>Gender</th>
<th>Status</th>

</tr>
<?php

    $con = mysql_connect("localhost", "root", "avtt123");

    mysql_select_db("arvintarrega",$con);

    $query = mysql_query("SELECT * FROM student");
    echo "<form action = attendance.php method = POST>";
    while($student=mysql_fetch_array($query))
    {   
    echo "<tr>";
    echo "<td><center>".$student['fname']."</center></td>";
    echo "<td><center>".$student['lname']."</center></td>";
    echo "<td><center>".$student['subject']."</center></td>";;  
    echo "<td><center>".$student['section']."</center></td>";
    echo "<td><center>".$student['gender']."</center></td>";
    echo '<td><center><input type = "checkbox" name = "status" value = "Present">Present</input>';
    echo '<input type = "checkbox" name = "status" value = "Absent">Absent</input>';
    echo '<input type = "checkbox" name = "status" value = "Excused">Excused</center></input></td>';
    }
    echo "</form>";
    echo "</table>";

    if(isset($_POST['save']))
    {
        if(empty($_POST['set_date']) && empty($_POST['status']))
        {
    if(isset($_POST['set_date']) && ($_REQUEST['status']=="Present"))
        {
            $sql = "INSERT INTO attendance(date, status) VALUES('$_POST[set_date]', '$_REQUEST[status]')"; 
            echo '<span style="color:green;"><strong>Attendance Complete!<strong></span>';
        }
        else if(isset($_POST['set_date']) && ($_REQUEST['status']=="Absent"))
        {
            $sql = "INSERT INTO attendance(date, status) VALUES('$_POST[set_date]', '$_REQUEST[status]')"; 
            echo '<span style="color:green;"><strong>Attendance Complete!<strong></span>';          
        }   
        else if(isset($_POST['set_date']) && ($_REQUEST['status']=="Excused"))
        {
            $sql = "INSERT INTO attendance(date, status) VALUES('$_POST[set_date]', '$_REQUEST[status]')"; 
            echo '<span style="color:green;"><strong>Attendance Complete!<strong></span>';      

        }
        mysql_query($sql, $con);
        }       
        else 
        echo '<span style="color:red;"><strong>All fields are required</strong></span>';
    }


    mysql_close();
  ?>

</br></br>   
<input type = "submit" name = "save" value = "Submit">
</form>
</center>
</body>
</html>

现在,您有了一个if语句来检查变量是否为空,因此以后的值永远不会为真。 删除此:

if(empty($_POST['set_date']) && empty($_POST['status']))
    {
    ...
    }

但是当然要把代码放在点上

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM