if(isset($ _ POST [' submit']))总是返回false

时间:2014-07-10 04:47:01

标签: php form-submit

我正在尝试创建一个每周参加学生出席的表格。但是当点击提交按钮时,它总是返回false。

我有表格的ff代码:

<?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>

用于将数据从表单插入数据库的php

<?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";
}
?>

输出始终为&#34;提交为false&#34;。

我无法弄清楚我的代码是否有问题。

3 个答案:

答案 0 :(得分:2)

您没有提交按钮的名称 尝试添加

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

答案 1 :(得分:1)

这是你正在做的错误。您期望viewattendance.php中的表单标记名称属性是错误的 改变行

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

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

答案 2 :(得分:0)

您将表单命名为“提交”而不是输入按钮。

替换此

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

使用您的代码

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