Skip to content
Advertisement

how can i send a value to other page via POST without Input Tag in PHP

How can I send a value to another page via POST without Input Tag in PHP? I tried this way but also it didn’t work.

the assisment the code

<?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");
?>

Advertisement

Answer

You can’t send form with ‘a href’. You can use button or input button and style it to look like a regular link (correct solution). Or you can use Javascript to handle link click and send form from javascript (bad workaround, but also working one).

Also if you want to get informations, you should use GET method which will also solve your problem.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement