[英]What is wrong with my sql query? It doesnt store the data
Please help me with my sql query . 请帮助我与我的SQL查询 。 I couldn't store the value of the checkbox and the date inside my database . 我无法在数据库中存储复选框的值和日期 。 Any solutions ? 有什么解决办法吗? If there aren't any. 如果没有的话。 What should I change? 我应该改变什么? I'm just a beginner when it comes to sql and php. 关于sql和php,我只是一个初学者。 Thanks in advance . 预先谢谢 。
<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>
You now have a if statement to check if your variables are empty, so therefor the values later on will never be true. 现在,您有了一个if语句来检查变量是否为空,因此以后的值永远不会为真。 Remove this: 删除此:
if(empty($_POST['set_date']) && empty($_POST['status']))
{
...
}
but of course leave the code on the dots 但是当然要把代码放在点上
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.