doubi1928 2014-07-10 04:47
浏览 64
已采纳

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

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.

  • 写回答

3条回答 默认 最新

  • dsovc00684 2014-07-10 04:49
    关注

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

    <input type="submit" name="submit" value="View Attendance Sheet"/>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭