這是index.php的一部分。此代碼用於顯示數據庫中的所有產品。如何從數據集(PHP)傳遞正確的ID?
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
}
?>
還有一個頁面叫做product.php。當用戶單擊index.php中的「更多詳情」按鈕時,它將重定向到product.php。
我想要做的是,當用戶點擊「更多詳細信息」按鈕時,我需要傳遞該頁面的正確產品ID。怎麼做?
添加一個(隱藏)表單字段,其中包含值? – jeroen
表單中的要點是什麼?只需添加一個標準錨並添加一個產品唯一標記的GET參數,例如該ID,例如product.php?id = idhere –
使用隱藏字段並傳遞您的ID。 –