![](/img/trans.png)
[英]How can I send input tag value from HTML file to PHP file without form tag?
[英]how can i send a value to other page via POST without Input Tag in PHP
如何在没有 PHP 输入标签的情况下通过 POST 将值发送到另一个页面? 我试过这种方式,但也没有奏效。
<?php
include("database/config.php");
include("database/opendb.php");
include("functions.php");
if (isset($_POST["totalHobbies"])) {
$par = $_POST["totalHobbies"];
}
$query = "SELECT firstname, lastname, hobbies, id ";
$query .= "FROM persons ";
$query .= "WHERE hobbies = ? ";
$preparendquery = $dbaselink->prepare($query);
$preparendquery->bind_param("i", $par);
$preparendquery->execute();
if ($preparendquery->errno) {
echo "Fout bij uitvoeren commando". "<br>";
} else {
$result = $preparendquery->get_result();
if ($result->num_rows === 0) {
echo "Geen rijen gevoenden" . "<br>" ;
} else {
while ($row = $result->fetch_assoc()) { // here is the problem
echo "<form action=\"details.php\" method='POST' >"; //refer to details.php page
$id = $row["id"];
echo "<a href=\"details.php?id= " . $row['id'] . " \">" . fullname($row['firstname'], $row['lastname']). "</a>". "<br>";
echo "<input type=\"hidden\" name = \"id\" value= '$id'> </input>";
echo "</form>";
};
}
}
$preparendquery->close();
echo"<br><button onclick=\"location.href='index.html'\">Back</button>";
include("database/closedb.php");
?>
您不能发送带有“a href”的表单。 您可以使用按钮或输入按钮并将其样式设置为看起来像常规链接(正确的解决方案)。 或者您可以使用 Javascript 来处理链接点击并从 javascript 发送表单(错误的解决方法,但也可以使用)。
此外,如果您想获取信息,您应该使用 GET 方法,这也可以解决您的问题。
我仍然没有正确理解你的问题。
删除<a>
标签
您的输入标签未正确写入。 它应该是
echo "<input type=\"hidden\" name = \"id\" value= '$id'/>";
您可以将id
作为会话变量,然后在 details.php 页面中调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.