Please help me with my sql query. 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. 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. Remove this:
if(empty($_POST['set_date']) && empty($_POST['status']))
{
...
}
but of course leave the code on the dots