这是我的PHP& HTML代码,一切正常,除了它给我一些错误,如“通知:未定义的索引:参加第43行的C:\ xampp \ htdocs \ ams \ postattentry.php”
<?php
require_once("./include/membersite_config.php");
if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("index.php");
exit;
}
include('header.php');
?>
<div class="row-fluid sortable">
<div class="box span8">
<div class="box-header well" data-original-title>
<h2><i class="icon-edit"></i> Attendance Entry</h2>
</div>
<div class="box-content">
<?php
$hour=$_GET["hour"];
$date=$_GET["date"];
$year=$_GET["year"];
$sem=$_GET["sem"];
$sec=$_GET["sec"];
$dept=$_GET["dept"];
$bat=$_GET["bat"];
if((strpos($fgmembersite->UserAttrib(),"i")>0) and $fgmembersite->attentrycheck($hour,$date,$year,$sem,$sec,$dept,$bat,$fgmembersite->Userempid()))
{
$error = $fgmembersite->GetErrorMessage();
if(!empty($error))
{
echo '<div class="alert alert-info">';
echo $error;
echo '</div>';
}
if(!$fgmembersite->DBLogin())
{
die("Error Locating the Students Database.");
}
if($bat=="ALL")
{
$qryae = "Select * from $fgmembersite->studtblname where dept='$dept' and year='$year' and sem='$sem' and sec='$sec'";
}
else
{
$qryae = "Select * from $fgmembersite->studtblname where dept='$dept' and year='$year' and sem='$sem' and sec='$sec' and bat='$bat'";
}
if(!($uapae=mysql_query( $qryae ,$fgmembersite->connection)))
{
die("Error Locating the Students Database.");
}
echo '<table class="table table-striped table-bordered">';
echo '<thead>';
echo '<tr>';
echo '<td align="center">S.No.</td>';
echo '<td align="center">Roll No.</td>';
echo '<td>Student Name</td>';
echo '<td align="center">Attendance</td>';
echo '</tr>';
echo '</thead>';
echo '<form id="attentry" class="form-horizontal" action="postattentry.php" method="post">';
echo '<tbody>';
$i=0;
$j=1;
while ($uapres = mysql_fetch_array($uapae)) {
echo '<tr>';
echo "<td>{$j}</td>";
echo "<td>{$uapres['rollno']}<input type='hidden' name='rollno[$i]' value='{$uapres['rollno']}' /></td>";
echo "<td>{$uapres['sname']}</td>";
echo "<td><div class='control-group'>
<div class='controls'>
<label class='checkbox'>
<input type='checkbox' name='attend[$i]' id='attend[$i]' value='1' checked=''/>
</label>
</div>
</div></td>";
echo '</tr>';
++$i;
++$j;
}
echo '<tr>';
echo '<td align="center">Total</td>';
echo '<td align="center">Hour</td>';
echo '<td>Date</td>';
echo '<td align="center">Year</td>';
echo '</tr>';
echo '<tr>';
echo "<td>{$i}<input type='hidden' name='fcount' id='fcount' value='{$i}'/></td>";
echo "<td>{$hour}<input type='hidden' name='fhour' id='fhour' value='{$hour}'/></td>";
echo "<td>{$date}<input type='hidden' name='fdate' id='fdate' value='{$date}'/></td>";
echo "<td>{$year}<input type='hidden' name='fyear' id='fyear' value='{$year}'/></td>";
echo '</tr>';
echo '<tr>';
echo '<td align="center">Dept.</td>';
echo '<td align="center">Sem</td>';
echo '<td>Section</td>';
echo '<td align="center">Batch</td>';
echo '</tr>';
echo '<tr>';
echo "<td>{$dept}<input type='hidden' name='fdept' id='fdept' value='{$dept}'/></td>";
echo "<td>{$sem}<input type='hidden' name='fsem' id='fsem' value='{$sem}'/></td>";
echo "<td>{$sec}<input type='hidden' name='fsec' id='fsec' value='{$sec}'/></td>";
echo "<td>{$bat}<input type='hidden' name='fbat' id='fbat' value='{$bat}'/></td>";
echo '</tr>';
echo '<tr>';
echo "<td></td>";
echo "<td><button type='submit' name='submit' value='Submit' class='btn btn-primary'>Register</button></td>";
echo "<td><button type='reset' class='btn'>Reset</button></td>";
echo "<td></td>";
echo '</tr>';
echo '</tbody>';
echo '</form>';
echo '</table>';
}?>
</div>
</div><!--/span-->
</div><!--/row-->
<?php include('footer.php'); ?>
处理表格代码是......
<?php
require_once("./include/membersite_config.php");
if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("index.php");
exit;
}
include('header.php');
?>
<div class="row-fluid sortable">
<div class="box span8">
<div class="box-header well" data-original-title>
<h2><i class="icon-edit"></i> Post Attendance Entry</h2>
</div>
<div class="box-content">
<?php
echo $hour=$_POST['fhour'];
echo $date=$_POST['fdate'];
echo $year=$_POST['fyear'];
echo $sem=$_POST['fsem'];
echo $sec=$_POST['fsec'];
echo $dept=$_POST['fdept'];
echo $bat=$_POST['fbat'];
echo $count=$_POST['fcount'];
if(!$fgmembersite->DBLogin())
{
die("Error Locating the Students Database.");
}
if(!$fgmembersite->EnsureAttTable())
{
die("Unable to Create Attendance Table.");
}
$attvars = array();
$i = 0;
while ($i < $count) {
echo $rollno= $_POST['rollno'][$i];
echo $attend= $_POST['attend'][$i];
++$i; }
?>
</div>
</div><!--/span-->
</div><!--/row-->
<?php include('footer.php'); ?>
我通过将输入类型从复选框更改为文本来尝试相同的代码,它运行正常。我无法弄清楚问题出在哪里。
答案 0 :(得分:3)
在表单中,如果未选中复选框,则不会发布。
变化:
echo $attend= $_POST['attend'][$i];
为:
if(isset($_POST['attend']) && isset($_POST['attend'][$i]){
echo $attend =$_POST['attend'][$i]
} else {
echo $attend =0; //or whatever value you wish
}
答案 1 :(得分:0)
如果未选中复选框,则不会将其作为POST变量发送。
为了识别未选中复选框,您必须执行逻辑步骤。
if (isset($_POST[attend[$i]])){
{
$attended=1;
}else{
$attended=0;
}
我正式太慢了。