[英]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.