Question

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

Was it helpful?

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"];

OTHER TIPS

Are you sure you meant to do $search=$_POST["search"];?

If you're sending it in the URL, you'll need to do $search=$_GET["search"]; instead.

Your link is a $_GET not $_POST change

$search=$_POST["search"];

to

$search = $_GET['search'];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top