if(isset($_POST['submit'])) always return false

user3823901

I am trying to create a form that takes the attendance of the students weekly. But when the submit button is click it always return to false.

I have the ff code for the form:

<?php

require_once 'db2.php';

$subject = $_POST['subject'];
$section = $_POST['section'];
$query = mysql_query ("SELECT * FROM Subject where Subj_Code='$subject'") or die ('select all query error');
?>
<h5>Students attendance to your Class(
<?php while ($row = mysql_fetch_array($query))
{
echo $row['Subject_Desc'];
}
?>) </h5>
<p>Week <select name="date"> 
<option value="1" SELECTED> 1 </option>
<option value="2" > 2 </option>
<option value="3" > 3 </option>
<option value="4" > 4 </option>
<option value="5" > 5 </option>
<option value="6" > 6 </option>
<option value="7" > 7 </option>
<option value="8" > 8 </option>
<option value="9" > 9 </option>
<option value="10" > 10 </option>
<option value="11" > 11 </option>
<option value="12" > 12 </option>
<option value="13" > 13 </option>
<option value="14" > 14 </option>
<option value="15" > 15 </option>
<option value="16" > 16 </option>
<option value="17" > 17 </option>
<option value="18" > 18 </option>
</select>

<table border="1">
<tr>
    <td style="background-color:pink;width:120px;"><center> Student Name </center></td>
    <td style="background-color:pink;width:120px;"><center> Attendance </center></td>

</tr>

<form action="viewattendance.php" method="post" name="submit">
<?php
$result = mysql_query("SELECT student.*, subjectsection.* from subjectsection INNER JOIN student ON student.section_ID=subjectsection.section_ID Where subjectsection.Subj_Code= '$subject' AND subjectsection.section_ID='$section' ORDER BY student.LName");


while($row=mysql_fetch_array($result))
{
echo " <tr> ";
echo "<td><center> " .$row['FName']. " " .$row['LName']. "</center></td>";
echo "<td><center><input type='checkbox' value='".$row['Student_ID']."' name='week[]'></center></td>";
echo "</tr>";
}
?>
</table>
<input type="hidden" value="<?php echo $subject ?>" name="subject">
<input type="hidden" value="<?php echo $section ?>" name="section">
<input type="submit" value="View Attendance Sheet"/>
</form>

The php for inserting the data from the form to the database

<?php
if(isset($_POST['submit'])) {
    $subject = $_POST['subject'];
    $section = $_POST['section'];
    $Week= $_POST['date'];
    $Student = $_POST['week'];
    $length = count($Student);

    $qry = "DELETE FROM attendancecheck WHERE Week = '" . $Week . "'"; 

    for ($i = 0; $i < $length; $i++) {
        if ($i < ($length - 1)) {
            $qry = "INSERT INTO attendancecheck ( Student_ID , Week , Subj_Code, Present) VALUES ('$Student[i]' ,  '$Week' , '$subject', '1')";
            $result = mysql_query ($qry);
        }
        else {
            echo "length is zero";
        }
    }
}
else {
echo "submit is false";
}
?>

The output was always "submit is false".

I can't figure out if what is wrong with my code.

Vidya L

You don't have name for the submit button try to add

<input type="submit" name="submit" value="View Attendance Sheet"/>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related