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 vue使用gojs,需求在link中的虚线上添加方向箭头
  • ¥15 CSS通配符清除内外边距为什么可以覆盖默认样式?
  • ¥15 SPSS分类模型实训题步骤
  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么
  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红