0

Trying to display results that are clickable.

<form method="post" action="AF9.php">
            <input type="submit" name="submit" value=" search ">
            <input type="text" name="search" />
</form>

and here is partially the AF9.php file:

<?php

        $connection = @new mysqli(HOSTNAME, MYSQLUSER, MYSQLPASS, MYSQLDB);
        if ($connection->connect_error) {
         die('Connect Error: ' . $connection->connect_error);
        }
        else {

        $search=$_POST["search"];

        $query="SELECT *,  FROM comments AS c JOIN namestable2 AS w ON c.w1 = w.w1
        WHERE name like '%$search%' 
        ORDER BY name DESC";                         
        $connection->query("SET NAMES utf8");               
        $result_obj = '';
        $result_obj = $connection->query($query);             

        while($result = $result_obj->fetch_array(MYSQLI_ASSOC)) {   
        $items[] = $result;
        }                               

        foreach ($items as $item) {
        echo('<a href="AF9.php?search='.$item['word'].'">'.$item['word'].'</a>');

}?>

however when I click on the result, it says "Undefined index: search". Please help

4

3 回答 3

1

以“?key=value”结尾的硬编码链接,如“?search=xyz”,将通过 GET 流,而不是 POST。尝试改变这个:

$search=$_POST["search"];

对此:

$search=$_GET["search"];
于 2013-10-09T01:48:35.653 回答
1

你确定你是故意的$search=$_POST["search"];吗?

如果您在 URL 中发送它,则需要这样做$search=$_GET["search"];

于 2013-10-09T01:48:54.197 回答
0

您的链接是 $_GET 而不是 $_POST 更改

$search=$_POST["search"];

$search = $_GET['search'];
于 2013-10-09T01:47:59.520 回答