php - 数组不向前传送数据

标签 php

我有一个表单,需要 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/

相关文章:

php - 包含持续时间的循环

php - 计算两个连续日期之间的最大天数

PHP登录系统任何密码都可以

php copy() 使速度更快

php - $_SESSION 的问题

php - 在初始化时从 Mysql 获取数据

php - Javascript、PHP、保存字段值

php - 每行返回多行(在 Zend Framework 中)

php - 将字符串 url 转换为 html 链接标签

php - 数据未保存在数据库 cakephp 中