当我执行下面的代码时,我的复选框数组长度为零。
<?PHP
if(isset($_POST['Submit3']))
{
$check = $_POST['checkList'];
echo count($check);
for($i=0;$i<count($check);$i++)
{
$id = $_POST['id'][$i];
$year = $_POST['year'][$i];
$month = $_POST['month'][$i];
$leaves = $_POST['leaves'][$i];
$working = $_POST['working'][$i];
$payment_days = $_POST['payment'][$i];
$bonus = $_POST['bonus'][$i];
$ctc = $_POST['ctc'][$i];
$basic = $_POST['basic'][$i];
$hra = $_POST['hra'][$i];
$sa = $_POST['sa'][$i];
$ma = $_POST['ma'][$i];
$con = $_POST['con'][$i];
$ta = $_POST['ta'][$i];
$pf = $_POST['pf'][$i];
$pt = $_POST['pt'][$i];
$vpf = $_POST['vpf'][$i];
$net_pay = $_POST['netpay'][$i];
$result = mysql_query("INSERT INTO salaries(employee_id,ctc,basic_pay,hra,special_allowances,medical_allowances,travell_allowances,conveyance,provident_fund,professional_tax,vpf,bonus,working_days,leaves,payment_days,net_pay,month,year)VALUES('$id','$ctc','$basic','$hra','$sa','$ma','$ta','$con','$pf','$pt','$vpf','$bonus','$working','$leaves','$payment_days','$net_pay','$month','$year')") or die(mysql_error());
if($result)
{
$scount++;
header("Location:?pid=employee_management/view-emp&minsert=success");
}
else
{
header("Location:?pid=employee_management/run-payroll&insert=fail");
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#example').dataTable( {
"sPaginationType": "full_numbers"
} );
} );
</script>
<script type="application/javascript">
function delrow() {
var ok=confirm("Are you sure want to delete");
if(ok)
return true;
else
return false;
}
</script>
<script type="text/javascript">
function validate()
{
if(document.frmreg.year.value == "")
{
alert("Please Select Year.\n")
document.frmreg.year.focus();
return false;
}
if(document.frmreg.month.value == "")
{
alert("Please Select Month.\n")
document.frmreg.month.focus();
return false;
}
}
function no_of_days(mo,ye)
{
var m=parseInt(mo);
var y=parseInt(ye);
var days="";
if((m==1) || (m==3) || (m==5) || (m==7) || (m==8) || (m==10) || (m==12))
{
days = 31;
}
else if((m==4) || (m==6) || (m==9) || (m==11))
{
days = 30;
}
else if(m==2)
{
if(((y%4==0)&&(y%100!=0))||(y%400==0))
{
days = 29;
}
else
{
days = 28;
}
}
document.frmreg.no_days.value = days;
}
</script>
<link href="../../css/estilos.css" rel="stylesheet" type="text/css" />
<link href="../../css/demo_table.css" rel="stylesheet" type="text/css" />
</head>
<body onLoad="document.frmreg.search2.focus()">
<?PHP
if ($_GET['insert']=="fail")
{
$strr= "Salaries not Inserted";
}
?>
<table width="830" border="0" align="center" cellpadding="0" cellspacing="3">
<tr>
<td height="30" class="heading5">Run Payroll</td>
<td height="30" colspan="9" class="txnormalbold"><?PHP echo $strr; ?></td>
</tr>
<form name="frmreg" id="frmreg" method="post" action="" onsubmit="return validate()">
<tr>
<td height="60" width="236" align="center" class="txnormalbold"> Year :
<select name="year" id="year" class="formfield" style="width:120px;" onchange="return no_of_days(document.frmreg.month.value,this.value)">
<option value="">--- Select ---</option>
<?php
for ($x=2010; $x<=2050; $x++)
{
echo'<option value="'.$x.'">'.$x.'</option>';
}
?>
</select><span style="color:#000099">*</span></td>
<td width="200" align="left" class="txnormalbold"> Month :
<select name="month" id="month" class="formfield" style="width:120px;" onchange="return no_of_days(this.value,document.frmreg.year.value)">
<option value="">--- Select ---</option>
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select><span style="color:#000099">*</span></td>
<td width="161" align="left" class="txnormalbold">Working days :
<input type="text" name="no_days" id="no_days" class="formfield" style="width:50px;" /></td>
<td width="72" align="left"><input type="submit" name="dsubmit" id="dsubmit" value="Submit" class="testfield_button" /></td>
<td width="71"></td>
<td width="40"></td>
<td width="11"></td>
<td width="2"></td>
<td width="2"></td>
<td width="2"></td>
</tr>
</form>
<?PHP
if(isset($_POST['dsubmit']))
{
$n_d = $_POST['no_days'];
$mnth = $_POST['month'];
$m_r = mysql_query("SELECT * from months where id='$mnth'");
$m_arr = mysql_fetch_array($m_r);
$month1 = $m_arr['name'];
$yr = $_POST['year'];
?>
<form name="fmreg" id="fmreg" method="post" action="">
<tr>
<td height="40" class="txnormalboldred" colspan="2" align="right" >Payroll for the Month of <?PHP echo ucfirst($month1); ?>/<?PHP echo $yr; ?></td>
<td width="72" align="right"><input type="button" name="checkall2" id="checkall2" value="Check All" onclick="javascript:markAll()" class="careermanage" /></td>
<td width="71" align="left"><input type="button" name="checkall22" id="checkall22" value="Uncheck" onclick="javascript:unMarkAll()" class="careermanage" /></td>
<td class="txnormalboldred" colspan="6" align="center" > </td>
</tr>
<tr>
<td colspan="10" style="font-family:Arial, Helvetica, sans-serif; font-size:14px"> <table width="830" border="0" cellpadding="0" cellspacing="0" class="display" id="example" style="font-family:Arial, Helvetica, sans-serif; font-size:14px">
<thead>
<tr>
<td align="right" valign="middle" class="txnormalbold"><table width="830" border="0" cellpadding="0" cellspacing="0" class="display" id="example2" style="font-family:Arial, Helvetica, sans-serif; font-size:14px">
<thead>
<tr>
<th width="3%" ></th>
<th width="5%" align="center">Emp. Id</th>
<th width="7%" align="center">Name</th>
<th width="5%" align="center">Basic</th>
<th width="5%" align="center">HRA</th>
<th width="5%" align="center">Spl. All.</th>
<th width="5%" align="center">Med. All.</th>
<th width="5%" align="center">Tra. All.</th>
<th width="5%" align="center">Conv.</th>
<th width="5%" align="center">Pro. Fund</th>
<th width="5%" align="center">Prof. Tax</th>
<th width="5%" align="center">Net Inc.</th>
</tr>
</thead>
<tfoot>
<tr>
<th width="3%" ></th>
<th width="5%" align="center">Emp. Id</th>
<th width="7%" align="center">Name</th>
<th width="5%" align="center">Basic</th>
<th width="5%" align="center">HRA</th>
<th width="5%" align="center">Spl. All.</th>
<th width="5%" align="center">Med. All.</th>
<th width="5%" align="center">Tra. All.</th>
<th width="5%" align="center">Conv.</th>
<th width="5%" align="center">Pro. Fund</th>
<th width="5%" align="center">Prof. Tax</th>
<th width="5%" align="center">Net Inc.</th>
</tr>
</tfoot>
<tbody>
<?php
$sel=mysql_query("select * from employees");
$count = mysql_num_rows($sel);
while($res=mysql_fetch_array($sel))
{
$eid = $res['employee_id'];
$ename = $res['employee_first_name'];
$ctc = $res['mctc'];
$basic = $res['mbasic_pay'];
$hra = $res['mhra'];
$sa = $res['mspecial_allowances'];
$ma = $res['mmedical_allowances'];
$ta = $res['mtravell_allowances'];
$con = $res['mconveyance'];
$pf = $res['mprovident_fund'];
$pt = $res['mprofessional_tax'];
$one_day_base = $basic/30;
$tot_basic = ($n_d*$one_day_base);
$tot_ear = $tot_basic + $hra + $sa + $ma + $ta + $con;
$tot_ded = $pf + $pt;
$net_pay = round($tot_ear - $tot_ded);
?>
<tr>
<td height="24" align="center"><input type="checkbox" name="checkList[]" id="checkList[]" value="<?php echo $eid;?>"/></td>
<td height="24" align="center"><?php echo $eid;?></td>
<td height="24" align="center"><?php echo $ename;?></td>
<td height="24" align="center" ><?php echo $basic;?></td>
<td height="24" align="center" ><?php echo $hra;?></td>
<td height="24" align="center"><?php echo $sa;?></td>
<td height="24" align="center"><?php echo $ma;?> </td>
<td height="24" align="center"><?php echo $ta;?></td>
<td height="24" align="center"><?php echo $con;?></td>
<td height="24" align="center"><?php echo $pf;?></td>
<td height="24" align="center"><?php echo $pt;?></td>
<td height="24" align="center"><?PHP echo number_format(round($net_pay),2);?> </td>
</tr>
<input type="hidden" name="id[]" id="id" value="<?PHP echo $eid; ?>" />
<input type="hidden" name="year[]" id="year" value="<?PHP echo $yr; ?>" />
<input type="hidden" name="month[]" id="month" value="<?PHP echo $mnth; ?>" />
<input type="hidden" name="leaves[]" id="leaves" value="0" />
<input type="hidden" name="working[]" id="working" value="<?PHP echo $n_d; ?>" />
<input type="hidden" name="payment[]" id="payment" value="<?PHP echo $n_d; ?>" />
<input type="hidden" name="bonus[]" id="bonus" value="0"/>
<input type="hidden" name="ctc[]" id="ctc" value="<?PHP echo $ctc; ?>" />
<input type="hidden" name="basic[]" id="basic" value="<?PHP echo $basic; ?>" />
<input type="hidden" name="hra[]" id="hra" value="<?PHP echo $hra; ?>" />
<input type="hidden" name="sa[]" id="sa" value="<?PHP echo $sa; ?>" />
<input type="hidden" name="ma[]" id="ma" value="<?PHP echo $ma; ?>" />
<input type="hidden" name="con[]" id="con" value="<?PHP echo $con; ?>"/>
<input type="hidden" name="ta[]" id="ta" value="<?PHP echo $ta; ?>"/>
<input type="hidden" name="pf[]" id="pf" value="<?PHP echo $pf; ?>" />
<input type="hidden" name="pt[]" id="pt" value="<?PHP echo $pt; ?>" />
<input type="hidden" name="vpf[]" id="vpf" value="<?PHP $res['vpf']; ?>" />
<input type="hidden" name="netpay[]" id="netpay" value="<?PHP $net_pay; ?>"/>
<?php
} // end of while
?>
</tbody>
</table></td></tr>
</thead>
</table>
</td>
</tr>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit3" id="Submit3" value="Run Payroll" class="testfield_button" /></td>
<td colspan="6"></td>
</tr>
</form>
<?php
}
?>
</table>
</body>
</html>
如何获取数组长度?,是否正确?,如果上述代码中出现任何错误请更正。 提前谢谢。