每当我尝试在数据库表中插入多行时,只插入1行。我已经尝试了所有方法,仍然无法一次插入所有行。这是我的HTML代码
<?php
error_reporting(0);
include ('includes/workprogress_func.php');
?>
<body>
</ul>
</div>
<div id="rightcol">
<div id="Content" align="center">
<h1 align="center">Workplan Progress Form</h1>
<div id="table1" class="container" align="left">
<form name="form1" action="" method="post">
<table width="398" height="118" border="0" align="left" >
<td>
<tr>
<td > <p>Division Name:</p> </td>
<td> <input name="divisionname" type="text" value="" /></td>
</tr>
<tr>
<td><p>Division Chief: </p></td>
<td>
<input type="text" name="divisionchief" /></td>
</tr>
<tr>
<td><p> Period: </p> </td>
<td>
<input type="text" name="period" /></td>
</tr>
<tr>
<td><p> Month:</p> </td>
<td>
<input type="month" name="month" > </td>
</tr>
</table>
</div>
<div id="table2">
<table border="1" align="center" cellpadding="1" cellspacing="1" >
<tr>
<td rowspan="2" align="center"> SN </td>
<td rowspan="2" align="center"> Activity Name </td>
<td rowspan="2" align="center" > Unit </td>
<td rowspan="2" align="center"> Weightage </td>
<td colspan="4" align="center"> Performance Indicators(Percentage)</td>
<td colspan="3" align="center"> Performance Achievement </td>
<td colspan="2" align="center"> Indicator Measurement Basis </td>
<tr>
<td align="center">100 </td>
<td align="center"> 75</td>
<td align="center"> 50 </td>
<td align="center"> <50 </td>
<td align="center">Measurement </td>
<td align="center"> Score</td>
<td align="center"> Progress </td>
</tr>
<tr>
<td width:60px > 1</td>
<td> <input type="text" name="activityname[]" style="width:100px"/> </td>
<td> <input type="text" name="unit[]" style="width:50px" /> </td>
<td> <input type="text" name="weightage[]" style="width:80px"/> </td>
<td> <input type="text" name="per100[]" style="width:50px"/> </td>
<td> <input type="text" name="per75[]" style="width:50px" /> </td>
<td> <input type="text" name="per50[]" style="width:50px"/> </td>
<td> <input type="text" name="perless50[]" style="width:50px"/> </td>
<td> <input type="text" name="measurement[]" style="width:100px"/> </td>
<td> <input type="text" name="score[]" style="width:50px"/> </td>
<td> <input type="text" name="progress[]" style="width:80px"/> </td>
<td> <input type="text" name="indicatormeasure[]" style="width:150px"/> </td>
</tr>
<tr>
<td width:60px > 2</td>
<td> <input type="text" name="activityname[]" style="width:100px"/> </td>
<td> <input type="text" name="unit[]" style="width:50px" /> </td>
<td> <input type="text" name="weightage[]" style="width:80px"/> </td>
<td> <input type="text" name="per100[]" style="width:50px"/> </td>
<td> <input type="text" name="per75[]" style="width:50px" /> </td>
<td> <input type="text" name="per50[]" style="width:50px"/> </td>
<td> <input type="text" name="perless50[]" style="width:50px"/> </td>
<td> <input type="text" name="measurement[]" style="width:100px"/> </td>
<td> <input type="text" name="score[]" style="width:50px"/> </td>
<td> <input type="text" name="progress[]" style="width:80px"/> </td>
<td> <input type="text" name="indicatormeasure[]" style="width:150px"/> </td>
</tr>
<tr>
<td width:60px > 3</td>
<td> <input type="text" name="activityname[]" style="width:100px"/> </td>
<td> <input type="text" name="unit[]" style="width:50px" /> </td>
<td> <input type="text" name="weightage[]" style="width:80px"/> </td>
<td> <input type="text" name="per100[]" style="width:50px"/> </td>
<td> <input type="text" name="per75[]" style="width:50px" /> </td>
<td> <input type="text" name="per50[]" style="width:50px"/> </td>
<td> <input type="text" name="perless50[]" style="width:50px"/> </td>
<td> <input type="text" name="measurement[]" style="width:100px"/> </td>
<td> <input type="text" name="score[]" style="width:50px"/> </td>
<td> <input type="text" name="progress[]" style="width:80px"/> </td>
<td> <input type="text" name="indicatormeasure[]" style="width:150px"/> </td>
</tr>
<tr>
<td width:60px > 3</td>
<td> <input type="text" name="activityname[]" style="width:100px"/> </td>
<td> <input type="text" name="unit[]" style="width:50px" /> </td>
<td> <input type="text" name="weightage[]" style="width:80px"/> </td>
<td> <input type="text" name="per100[]" style="width:50px"/> </td>
<td> <input type="text" name="per75[]" style="width:50px" /> </td>
<td> <input type="text" name="per50[]" style="width:50px"/> </td>
<td> <input type="text" name="perless50[]" style="width:50px"/> </td>
<td> <input type="text" name="measurement[]" style="width:100px"/> </td>
<td> <input type="text" name="score[]" style="width:50px"/> </td>
<td> <input type="text" name="progress[]" style="width:80px"/> </td>
<td> <input type="text" name="indicatormeasure[]" style="width:150px"/> </td>
</tr>
</table>
</br>
</div>
<div align="center"> <input name="submit" type="submit" value="Submit" />
<label>
<input name="h" type="hidden" id="h" value="0" />
</label>
</form>
</div>
</div>
</div>
</body>
</html>
这是我的用于插入的PHP代码
<?php
if (isset($_POST['submit'])) {
include('includes/connect.php');
$num = $_POST['h'];
for ($i=0; $i<=$num; $i++)
{
$divisionname=$_POST['divisionname'];
$divisionchief=$_POST['divisionchief'];
$period=$_POST['period'];
$month=$_POST['month'];
$activityname=$_POST['activityname'][$i];
$unit=$_POST['unit'][$i];
$weightage=$_POST['weightage'][$i];
$per100=$_POST['per100'][$i];
$per75=$_POST['per75'][$i];
$per50=$_POST['per50'][$i];
$perless50=$_POST['perless50'][$i];
$measurement=$_POST['measurement'][$i];
$score=$_POST['score'][$i];
$progress=$_POST['progress'][$i];
$indicatormeasure=$_POST['indicatormeasure'][$i];
$sql="INSERT INTO `workplan_progress` (`name`, `chief`, `timePeriod`, `workMonth`, `activity_names`, `workUnit`, `workWeightage`, `percent_100`, `percent_75`, `percent_50`, `percent_less50`, `Measure`, `Score`, `Progress`, `indicator_measure`) VALUES ('$divisionname', '$divisionchief', '$period', '$month', '$activityname', '$unit', '$weightage', '$per100', '$per75', '$per50', '$perless50', '$measurement', '$score', '$progress', '$indicatormeasure')";
mysql_query($sql);
//echo "$sql";
//header("location:workplan.php");
}
echo"This information has been added to the database.";
}
?>
有人可以帮帮我!!!
答案 0 :(得分:-1)
<input name="h" type="hidden" id="h" value="0" />
$num = $_POST['h'];
for ($i=0; $i<=$num; $i++)
value = 0且0&lt; = 0只是一个循环; - )
你将html h设置为0,所以$ num总是0。 您可以通过
将$ num设置为提交的行数$num = count($_POST['activityname']);
但只有在您填写活动名称字段时才有效,或者您可以将$ num设置为行数。