我如何通过POST在PHP中没有输入标签的情况下将值发送到其他页面
我如何通过POST在PHP中没有输入标签的情况下将值发送到其他页面,我尝试过这种方式,但是也没有用
PHP
<?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发送表单(不好的解决方法,但是也可以解决)。
我仍然无法正确理解您的问题。
删除<a>
标签
您的输入标签未正确写入。应该是
echo "<input type=\"hidden\" name = \"id\" value= '$id'/>";