可点击的结果在PHP

时间:2013-10-09 01:42:39

标签: php mysql clickable

尝试显示可点击的结果。

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

这里部分是AF9.php文件:

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

}?>

然而,当我点击结果时,它会显示“Undefined index:search”。请帮忙

3 个答案:

答案 0 :(得分:1)

以“?key = value”结尾的硬编码链接(如“?search = xyz”)将通过GET流传递,而不是POST。尝试更改此内容:

$search=$_POST["search"];

到此:

$search=$_GET["search"];

答案 1 :(得分:1)

您确定要做$search=$_POST["search"];吗?

如果您是通过网址发送的,则需要执行$search=$_GET["search"];

答案 2 :(得分:0)

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

$search=$_POST["search"];

$search = $_GET['search'];