PHP search function - erroneous results
<p>I'm trying to create a simple search function in php, the user inserts his search query in a textbox:</p>

<pre><code>&lt;form action="inc/search.inc.php" method="post"&gt;
            &lt;input id="searchbox" name="search" class="search" type="text"&gt;&lt;/input&gt;
            &lt;/form&gt;
</code></pre>

<p>My search.inc.page redirects the user to an URL with the query:</p>

<pre><code>&lt;?php
if ($_SERVER["REQUEST_METHOD"] == "POST"
        &amp;&amp; !empty($_POST["search"]))
{
        $searchquery=$_POST["search"];
        header("Location: ../search.php?qr=".$searchquery);
}
?&gt;
</code></pre>

<p>My search.php calls the function retrieveSearch:</p>

<pre><code>&lt;?php 
include_once 'inc/functions.inc.php';
include_once 'inc/db.inc.php';

$db2 = new PDO(DB_INFO, DB_USER, DB_PASS);
$qr = (isset($_GET["qr"])) ? (string) $_GET["qr"] : NULL;

$e2 = retrieveSearch($db2, $qr);

$qresult = array_pop($e2);

echo $qresult;
 foreach ($e2 as $row)
 {
     echo $row["title"]."&lt;br/&gt;  ";
 }
?&gt;
</code></pre>

<p>retrieveSearch function:</p>

<pre><code>function retrieveSearch($db2, $qr=NULL)
{
    $sql2 = "SELECT id, title, resume, search
            FROM blog
            WHERE search LIKE ?";
    $stmt2 = $db2-&gt;prepare($sql2);
    $stmt2-&gt;execute(array($_GET["qr"]));
    $e2 = $stmt2-&gt;fetch();

    array_push($e2, $qr);
    return $e2;
}
</code></pre>

<p>Unfortunately, this is returning me some weird results, if for example I search for "fff" (one of my 'search' entries), I get the following:</p>

<pre><code>fff3
3
f
f
&lt;
&lt;
f
f
</code></pre>

<p>The 3 infront of 'fff' is the id - which I have no clue where it came from, the other characters seem to be the first letter/symbol of every column... even though I specifically said I only wanted the "title" column displayed.</p>
