PHP/MySQL Search Functionality
<p>I've followed <a href="http://www.startutorial.com/articles/view/php-crud-tutorial-part-1" rel="nofollow">this tutorial</a> thoroughly, and had success with it. However, it leads me to a dead end where I have to pay to access the tutorial on implementing a "Search" functionality to it. </p>

<p>I was wondering if anyone could help me out on how I can implement a search functionality given how the tutorial is constructed? Tutorials seems like they don't work with this. </p>

<p>I've tried this on a separate page so far, but it doesn't seem to work - also I don't know how it can be implemented on my actual site.</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
mysql_connect("localhost","root","") or die("could not connect");
mysql_select_db("kkp") or die("could not find db!");
$output ='';

//collect
if (isset($_POST['search'])){
    $searchq = $_POST['search'];
    $searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
    $query = mysql_query("SELECT * FROM personal_info WHERE FirstName LIKE '%$searchq%' OR SurName LIKE '%$searchq%'") or die("could not search");
    $count = mysql_num_rows($query);
    if($count == 0){
        $output = 'There was no search results!';
    }else{
        while($row = mysql_fetch_array($query)){
            $fname = $row['FirstName'];
            $lname = $row['SurName'];
            $id = $row['id'];

            $output .= '&lt;div&gt;'.$fname.''.$lname.'&lt;/div&gt;';
        }
    }
}
?&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Search&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form method="post" action="search.php"&gt;&lt;/form&gt;
        &lt;input type="text" name="search" placeholder="Search for student"&gt;
        &lt;input type="submit" value="Submit"&gt;
&lt;/body&gt;
&lt;/html&gt;

&lt;?php print("$output");?&gt;</code></pre>
</div>
</div>
</p>

<p>Also, here's where I'm trying to implement a search functionality. It just displays a table with the entries I've added to the database.</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="row"&gt;
    &lt;h3&gt;List of Student Volunteers&lt;/h3&gt;
&lt;/div&gt;
&lt;div class="row"&gt;
    &lt;table class="table table-striped table-bordered"&gt;
    &lt;thead&gt;
        &lt;tr&gt;
            &lt;td&gt;Name&lt;/td&gt;
            &lt;td&gt;Email Address&lt;/td&gt;
            &lt;td&gt;Mobile Number&lt;/td&gt;
            &lt;td&gt;Action&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
    &lt;?php
        include 'database.php';
        $pdo = Database::connect();
        $sql = 'SELECT * FROM personal_info ORDER BY id DESC';
        foreach ($pdo-&gt;query($sql) as $row) {
            echo '&lt;tr&gt;';
            echo '&lt;td&gt;'. $row['FirstName'] . '&lt;/td&gt;';
            echo '&lt;td&gt;'. $row['EmailAddress'] . '&lt;/td&gt;';
            echo '&lt;td&gt;'. $row['MobileNum'] . '&lt;/td&gt;';
            echo '&lt;td width=250&gt;';
            echo '&lt;a class="btn" href="read.php?id='.$row['id'].'"&gt;Read&lt;/a&gt;';
            echo ' ';
            echo '&lt;a class="btn" href="update.php?id='.$row['id'].'"&gt;Update&lt;/a&gt;';
            echo ' ';
            echo '&lt;a class="btn" href="delete.php?id='.$row['id'].'"&gt;Delete&lt;/a&gt;';
            echo '&lt;/td&gt;';
            echo '&lt;/tr&gt;';
        }
        Database::disconnect();
    ?&gt;</code></pre>
</div>
</div>
</p>