我有一个表单,需要 10 行类似的数据。该表格收集产品代码、描述和数量。我循环遍历 10 行并使用数组来收集信息。
$code = array();
$description = array();
$quantity = array();
<?php
for($i=0; $i<10; $i++){
?>
<div class="quote-row">
<div class="quote-id">
<?php echo $i+1; ?>
</div>
<div class="quote-code">
<input type="text" class="quotecode" name="<?php echo $code[$i]; ?>" />
</div>
<div class="quote-description">
<input type="text" class="quotedescription" name="<?php echo $description[$i]; ?>" />
</div>
<div class="quote-quantity">
<input type="text" class="quotequantity" name="<?php echo $quantity[$i]; ?>" />
</div>
</div>
<?php
}
?>
在接下来的页面上,我使用 $_POST['code'], $_POST['description'], $_POST['quantity']
来转发数据并尝试使用它。
我的问题是数据似乎没有到达?
使用 for 循环,我仍然能够提交表单并向前获取所有数据吗?
希望本文能提供尽可能多的信息,谢谢!
最佳答案
您正在名称属性中给出数组的值。你的数组是空的,所以你的名字也是空的。
试试这个:
<?php
for($i=0; $i<10; $i++){
?>
<div class="quote-row">
<div class="quote-id">
<?php echo $i+1; ?>
</div>
<div class="quote-code">
<input type="text" class="quotecode" name="code[]" />
</div>
<div class="quote-description">
<input type="text" class="quotedescription" name="description[]" />
</div>
<div class="quote-quantity">
<input type="text" class="quotequantity" name="quantity[]" />
</div>
</div>
<?php
}
?>
name[ ] 格式会自动使您的数据成为数组。
关于php - 数组不向前传送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9787178/