Search code examples
phpmysqlclickable

clickable results in php


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


Solution

  • Hardcoded links that end with "?key=value" like "?search=xyz" will pass via the GET stream, not the POST. Try changing this:

    $search=$_POST["search"];
    

    to this:

    $search=$_GET["search"];