-2

Here is my code:

<form name="pay" action="next.php" method="post">
<?php
while ($row = mysql_fetch_assoc($result)) {
?>
<tr>
<td><b>Contract Name</b></td>
<td><input type="text" name="project_name" value="<?php echo "$row[project_name]"; ?></td>
</tr>

<tr>
<td class="alt" ><b> Pay</b></td>
<td><input type="text" name="base_salary" id="base_salary" size=10 value="<?php echo "$row[project_name]"; ?>"></td>
</tr>

<tr>
<?php
}
?>
</tr>

<tr><td class="alt" ><input type="submit" id="submit" value="Compute"/></td></tr>
</form>

How to submit this while loop values to next.php page?

4

2 回答 2

1

change the input name from name="project_name" to name="project_name[]"

on the next php page

$project_name = $_POST['project_name'];
 for($i=0;$i<sizeof($project_name);$i++) 
{
// $project_name[$i]//  will give one value at a time for the textbox
}
于 2013-09-30T12:15:48.197 回答
0

第1步更改project_nameproject_name[]base_salarybase_salary[]

所以你的表单有两个这样的输入,

<input type="text" name="project_name[]" value="<?php echo "$row[project_name]"; ?>

<input type="text" name="base_salary[]" id="base_salary" size=10 value="<?php echo "$row[project_name]"; ?>">

第 2 步:在您的 next.php 中

$project_name=$_POST['project_name'];

$base_salary=$_POST['base_salary'];

foreach( $project_name as $key => $project )
{
  echo "The project name is $project and the base salary is $base_salary[$key]";
}
于 2013-09-30T12:25:13.207 回答