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

标签 php mysql checkbox

请帮助我处理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']))
    {
    ...
    }

但当然要把代码留在点上

关于php - 我的sql查询有什么问题?它不存储数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29192003/

相关文章:

php - SQL注入(inject)保护

javascript - 仅在单击两次后复选框才会取消选中

javascript - 如果选中将值添加到数组,则 react 复选框

php - 如何在 Linux 上安装旧的 CURL(我有旧的 PHP 版本)

mysql - 故障安全 mysql 查询插入与其他表中的验证值

php - 如何使用 href 以模式获取数据 ID?

mysql - 数据透视表错误

javascript - 如何使用 jQuery 或纯 JS 重置所有复选框?

javascript - 使用Ajax获取javascript变量的值?

php - 为什么概率结果的随机方差足够大?