dongshadu4498 2016-04-07 18:01
浏览 4

将数据发送到没有表单的其他页面

I was informed that I can send data without a POST function. What I am trying to figure out is how I can get rid of the form around my table and send the data to my page called "edit-product".

In addition to the data, I want the user to be sent there as well, just like the form's action attribute would do.

As of now, I have it structured like this:

<?php
        $stmt = $dbc->query("SELECT `id`,`first`,`last`,`product` FROM users");
        $stmt->setFetchMode(PDO::FETCH_ASSOC);

        while($row = $stmt->fetch()) {
        ?>
        <form method="POST" action="edit-product">
            <tr>
                <td><?php echo $row['id'];?>"</td>
                <td><?php echo $row['first'];?></td>
                <td><?php echo $row['last'];?></td>
                <td><?php echo $row['product'];?></td>
                <input name="id" type="hidden" value="<?php echo $row['id'];?>" readonly>
                <input name="first" type="hidden" value="<?php echo $row['first'];?>">
                <input name="last" type="hidden" value="<?php echo $row['last'];?>">
                <input name="product" type="hidden" value="<?php echo $row['product'];?>">
                <td><input name="save" type="submit" value="Save"></td>
                <td><div class="delete-class" name="delete" id="<?php echo $row['id']; ?>">Delete</div></td>
                <td><input name="edit" type="submit" value="Edit"></td>
            </tr>
        </form>
        <?php } ?>
        </tbody>
    </table>

In my edit-product page, I receive the data like this:

$id = $_POST['id'];
$first = $_POST['first'];
$last = $_POST['last'];
$product = $_POST['product'];

How could I do this?

  • 写回答

1条回答 默认 最新

  • dongyilai4214 2016-04-07 18:26
    关注

    You can use an edit button with anchor.

      <table>
         <tbody>
         <?php
            $stmt = $dbc->query("SELECT `id`,`first`,`last`,`product` FROM users");
            $stmt->setFetchMode(PDO::FETCH_ASSOC);
    
            while($row = $stmt->fetch()) {
            ?>       
                <tr>
                    <td><?php echo $row['id'];?>"</td>
                    <td><?php echo $row['first'];?></td>
                    <td><?php echo $row['last'];?></td>
                    <td><?php echo $row['product'];?></td>                    
                    <td><input name="save" type="submit" value="Save"></td>
                    <td><div class="delete-class" name="delete" id="<?php echo $row['id']; ?>">Delete</div></td>
                    <td><a href="/edit-product?id=<?php echo $row['id']; ?>&first=<?php echo $row['first'];?>&last=<?php echo $row['last'];?>&product=<?php echo $row['product'];?>">Edit</a></td>
                </tr>      
            <?php } ?>
            </tbody>
        </table>
    

    And u can catch the url value from edit-prpduct page. like

    $id = $_GET['id'];
    $first = $_GET['first'];
    $last = $_GET['last'];
    $product = $_GET['product'];
    

    Just try this without any form post.

    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥15 对于这个问题的算法代码
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题