请帮助我处理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/