dongxuanjiao0795 2015-05-06 09:26
浏览 28
已采纳

如何从数据集(PHP)传递正确的ID?

This is a part of index.php. This code is used to display the all the products in database.

 while($row = mysqli_fetch_array($result)) {?>     
      <form action="product.php?>" method="post">

           <tr class="info">
            <td align="center"><h3><?php echo $row['name'];?></h3></td>
          </tr>

          <tr class="success">
            <td align="center"><div class="grow pic"><img src="uploads/<?php echo $row['image'];?>"></div></td>
          </tr>

          <tr class="info">
            <td><?php echo substr($row['description'],0,75);?></td>
          </tr>

          <tr class="success">
            <td align="center"><input name="cart" type="submit" value="More Details"></td>
            </tr>

          <tr>
          <td></td>
          </tr>

      </form>
      <?php
      }
      ?>

There is a another page called product.php. When user click the "More details" button in index.php it will redirect to the product.php.

What I want to do is, I need to pass the correct product id for that page when user click the "more details" button. How to do it?

  • 写回答

4条回答 默认 最新

  • douniewei6346 2015-05-06 09:32
    关注

    like the comments say, add a hidden input tag to your form:

    <input name="id" type="hidden" value="<?=$row['id'];?>"/>
    

    then in product.php, you can access it by:

    $id = $_POST['id'];
    

    that's it..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?