[英]get value by id link with the href
這是我的輸入
<input type="text" name="quantity" id="quantity" value="1" />
這是我的href鏈接
<a href="UserOrderProduct.php?id=<?php echo $Pid; ?>
&price=<?php echo $Price; ?>&quantity=">add</a>
如何寫在href中,請忽略
<?php echo $Pid; ?>&price=<?php echo $Price; ?>
這是因為我已經從數據庫中獲得了 id 但只有數量而不是真正如何獲得它,可以教我嗎?
如果您有一個表單,您可以從代碼中獲得“數量”值:
<input type="text" name="quantity" id="quantity" value="1" />
如果您使用“GET”方法
<FORM method='get' action='next_script.php'>
所有值都將在地址中,否則,如果您發布值,您將通過 $_POST 數組在下一個腳本中獲取它們。
如果您需要在不同腳本之間傳遞一對或多對變量=值,最好的解決方案是使用 PHP 會話。
您只需要在每個腳本的開頭添加:
session_start();
並將 your_variable 和 your_value 設置為:
$_SESSION['your_variable'] = your_value;
或者
$_SESSION['session_variable'] = $your_variable;
這樣,數據在鏈接上不可見,您可以在任何您喜歡的地方訪問它們,前提是您將 session_start() 命令保留在每個 php 頁面的開頭。
如果您有 html...
<form method="post" action="phpfile.php">
<input type="text" name="quantity" id="quantity" value="1" />
<input type="submit" value="send">
</form>
...在您的 phpfile.php 中,您可以像這樣檢索數量的值:
<?php
$qty = $_POST['quantity'];
?>
<a href="UserOrderProduct.php?id=<?php echo $Pid; ?>
&price=<?php echo $Price; ?>&quantity=<?php echo $qty;?>">add</a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.