Php:提交回显td字段并添加新的td


Php: on submit echo td fields and ad new td

我有以下代码:

<form action="" method="POST">
<?php
$count = isset($_POST['count']) ? $_POST['count'] : 1;
if($count > 11) $count = 11;
?>
<table>
<!-- Keeps track of the current number of rows -->
<input type="hidden" name="count" value="<?php echo $count+1; ?>"/>
<?php for($i = 0; $i < $count; $i++): 
    // Loop through all rows gathering the data here, and then creating the fields below
    $val0 = isset($_POST['field'][$count]['0']) ? $_POST['field'][$count]['0'] : '';
    $val1 = isset($_POST['field'][$count]['1']) ? $_POST['field'][$count]['1'] : '';
    $val2 = isset($_POST['field'][$count]['2']) ? $_POST['field'][$count]['2'] : '';
?>
<tr>
    <td><input name="field[<?php echo $count; ?>][0]" value="<?php $val0; ?>"/></td>
    <td><input name="field[<?php echo $count; ?>][1]" value="<?php $val1; ?>"/></td>
    <td><input name="field[<?php echo $count; ?>][2]" value="<?php $val2; ?>"/></td>
</tr>
<?php endfor; ?>
</table>
<input type="submit" value="click me" />
</form>

问题是,当我按下提交它添加3个其他字段,但它清除其他字段。我如何保持字段的内容,但使它们不可编辑?

您没有重复您的值,您的$count应该是$i,因为您将以相同的字段名称

结束
<form action="" method="POST">
<?php
$count = isset($_POST['count']) ? $_POST['count'] : 1;
if($count > 11) $count = 11;
?>
<table>
<!-- Keeps track of the current number of rows -->
<input type="hidden" name="count" value="<?php echo $count+1; ?>"/>
<?php for($i = 0; $i < $count; $i++): 
    // Loop through all rows gathering the data here, and then creating the fields below
    $val0 = isset($_POST['field'][$i]['0']) ? $_POST['field'][$i]['0'] : '';
    $val1 = isset($_POST['field'][$i]['1']) ? $_POST['field'][$i]['1'] : '';
    $val2 = isset($_POST['field'][$i]['2']) ? $_POST['field'][$i]['2'] : '';
?>
<tr>
    <td><input name="field[<?php echo $i; ?>][0]" value="<?php echo $val0; ?>"/></td>
    <td><input name="field[<?php echo $i; ?>][1]" value="<?php echo $val1; ?>"/></td>
    <td><input name="field[<?php echo $i; ?>][2]" value="<?php echo $val2; ?>"/></td>
</tr>
<?php endfor; ?>
</table>
<input type="submit" value="click me" />
for($j=0;$j<3;$j++){
  echo '<input type="hidden" name="field['.$i.'][0]" value="'.$_POST[field][$i][0].'" />';
}