PHP循环 - 隐藏输入值 - SQL

时间:2015-03-11 13:14:47

标签: php html sql

我正在尝试一个接一个地显示多个行,下面有一个验证按钮,单击一个将转到更新(php)方法。我已经有了它,但它总是相同的值(第一个字母的姓氏)。

我需要尝试做的是让它在提交时从行中选择姓氏。这是代码:

<div class="container">
    <form action="update.php" method="POST">
        <?php
        //executes the SQL query
         $result = mysql_query("SELECT * FROM Sheet1");
         //returns the result from the database
         while ($row = mysql_fetch_array($result)) {
            $census = $row['Date'];
            $WebsiteAddress = $row['WebsiteAddress'];
            $LastName = $row['LastName'];

            echo "<input type='hidden' name='HiddenInput' value='".$LastName."'>";

            echo "<b>Last Name:</b> $LastName<br><br> <b>Website:</b> $WebsiteAddress<br><br> <b>Date:</b> $census<br><br>";

            echo "<input name='".$LastName."' type='submit' value='Verify' /><hr>";
         }
        ?>
    </form>
</div>

2 个答案:

答案 0 :(得分:0)

您需要创建输入数组以获取所有值,例如

<input type='hidden' name='HiddenInput[]' value='".$LastName."'>

然后$ _POST [&#39; HiddenInput&#39;]将返回包含$ LastName的所有值的数组

答案 1 :(得分:0)

看看这段代码..给所有隐藏字段赋予不同的名称..

 $i = 0;    
    while ($row = mysql_fetch_array($result)) {
                    $census = $row['Date'];
                    $WebsiteAddress = $row['WebsiteAddress'];
                    $LastName = $row['LastName'];

                    echo "<input type='hidden' name='HiddenInput_".$i."' value='".$LastName."'>";

                    echo "<b>Last Name:</b> $LastName<br><br> <b>Website:</b> $WebsiteAddress<br><br> <b>Date:</b> $census<br><br>";

                    echo "<input name='".$LastName."' type='submit' value='Verify' /><hr>";
                    $i++;
                 }