简体   繁体   English

通过带有 href 的 id 链接获取价值

[英]get value by id link with the href

this is my input这是我的输入

<input type="text" name="quantity" id="quantity" value="1" />

this is my href link这是我的href链接

<a href="UserOrderProduct.php?id=<?php echo $Pid; ?>
&price=<?php echo $Price; ?>&quantity=">add</a>

how to write it in the href and please ignore the如何写在href中,请忽略

<?php echo $Pid; ?>&price=<?php echo $Price; ?>

this is because i get the id already from the database but only the quantity not really how to get it, can teach me?这是因为我已经从数据库中获得了 id 但只有数量而不是真正如何获得它,可以教我吗?

If you have a form where you get the "quantity" value as it looks from your code:如果您有一个表单,您可以从代码中获得“数量”值:

<input type="text" name="quantity" id="quantity" value="1" />

if you use the "GET" method如果您使用“GET”方法

<FORM method='get' action='next_script.php'>

all the values will be in the address, otherwise, if you POST the values you'll get them in the next script via $_POST array.所有值都将在地址中,否则,如果您发布值,您将通过 $_POST 数组在下一个脚本中获取它们。

If you need to pass one or more couples variable=value between different scripts the best solution is to use PHP sessions.如果您需要在不同脚本之间传递一对或多对变量=值,最好的解决方案是使用 PHP 会话。

You just need to add at the beginning of each script:您只需要在每个脚本的开头添加:

session_start();

and put your_variable and your_value as:并将 your_variable 和 your_value 设置为:

$_SESSION['your_variable'] = your_value;

or或者

$_SESSION['session_variable'] = $your_variable;

In such a way data are not visible on the link and you can access them anywhere you like provided that you keep the session_start() command at the beginning of each php page.这样,数据在链接上不可见,您可以在任何您喜欢的地方访问它们,前提是您将 session_start() 命令保留在每个 php 页面的开头。

If you have html...如果您有 html...

<form method="post" action="phpfile.php"> 
<input type="text" name="quantity" id="quantity" value="1" />
<input type="submit" value="send">
</form>

...in your phpfile.php you can retrieve the value of quantity like this: ...在您的 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM