Php 如何在提交时为href赋值?

Php 如何在提交时为href赋值?,php,html,Php,Html,我命名了一个submit和一个href,当我测试条件时,submit工作,但href不工作,并且没有显示错误。如果您有任何帮助,我们将不胜感激 下面是代码 <form action="test.php" method="post"/> <a href="#" name="amhref" >Href</a> <input type ="submit" name="button" value="button"> </form> <?

我命名了一个submit和一个href,当我测试条件时,submit工作,但href不工作,并且没有显示错误。如果您有任何帮助,我们将不胜感激 下面是代码

<form action="test.php" method="post"/>
<a href="#" name="amhref" >Href</a>
<input type ="submit" name="button"  value="button">
</form>
<?php
if(isset($_POST['amhref'])){
echo ("<h1>I am href </h1>");
}else if(isset($_POST['button'])){
echo ("<h1>I am the button</h1>");
}
?>

链接

使用
控件来实现此目的。我使用了一个隐藏控件

<input type="hidden" name="id1" value="hello">


您不能使用
标记

标记不是表单类型的元素,这样您就无法在表单提交中传递给。如果要传递,请在输入类型文本中保留amhref值或将其隐藏

您还可以使用href和GET方法传递值

<form action="test.php" method="post"/>
<input type ="submit" name="button"  value="button">
</form>
<a href="?amhref" name="amhref" >Href</a>

<?php
  if(isset($_GET['amhref'])){
    echo ("<h1>I am href </h1>");
  }else if(isset($_POST['button'])){
    echo ("<h1>I am the button</h1>");
  }


不是表单元素。它将不会被提交。无法执行此操作,您必须使用
表单
标签,如
输入
为此,我们100%工作,感谢您的解释,我将在7分钟后打勾
<form action="test.php" method="post"/>
<input type ="submit" name="button"  value="button">
</form>
<a href="?amhref" name="amhref" >Href</a>

<?php
  if(isset($_GET['amhref'])){
    echo ("<h1>I am href </h1>");
  }else if(isset($_POST['button'])){
    echo ("<h1>I am the button</h1>");
  }