Link (on a while loop on a search query) inside a search form
<pre><code>echo "&lt;center&gt;&lt;form name = 'searching' method='POST' action='cpanel.php?manage=".$useraccounts."&amp;rcad=".$viewcustomer."'&gt;&lt;table border = 1&gt;";
        echo "&lt;select name = 'filter'&gt;";
        echo "&lt;option value ='username'&gt;Username&lt;/option&gt;";
        echo "&lt;option value ='username'&gt;Username&lt;/option&gt;";
        echo "&lt;/select&gt;";
        echo "  &lt;input name='search' type='text' &gt;   "; 
        echo "&lt;input type='submit' name='submit' value='Search'&gt; ";
        echo "&lt;input type='submit' name='back' value='Back'&gt;&lt;br&gt;&lt;br&gt;";
        echo "&lt;tr&gt;";
        echo "&lt;td&gt;User ID&lt;/td&gt;";
        echo "&lt;td&gt;Username&lt;/td&gt;";
        echo "&lt;td&gt;Last Name&lt;/td&gt;";
        echo "&lt;td&gt;First Name&lt;/td&gt;";
        echo "&lt;td&gt;Middle Initial&lt;/td&gt;";
        echo "&lt;td&gt;Address&lt;/td&gt;";
        echo "&lt;td&gt;Contact Number&lt;/td&gt;";
        echo "&lt;td&gt;Birthday&lt;/td&gt;";
        echo "&lt;td&gt;Date Registered&lt;/td&gt;"; 
        echo "&lt;td&gt;&amp;nbsp;&lt;/td&gt;";
        echo "&lt;/tr&gt;";

        $submit = $_POST['submit'];
        if(isset($submit)) {
        $search = $_POST['search'];
        $filter = $_POST['filter'];

            include "dbconnect.php";
            if ($search != NULL) {
            $searchquery = mysql_query("SELECT * FROM register WHERE $filter LIKE '%$search%'");
            while($fetchres = mysql_fetch_array($searchquery)) { //show search results

            $userid = $fetchres['userid'];
            $username = $fetchres['username'];
            $lname = $fetchres['lname'];
            $fname = $fetchres['fname'];
            $mi = $fetchres['mi'];
            $address = $fetchres['address'];
            $contact = $fetchres['contact'];
            $month = $fetchres['month'];
            $day = $fetchres['day'];
            $year = $fetchres['year'];
            $dateregistered = $fetchres['date'];
            $sendmessage = "&lt;a href = 'cpanel.php?manage=".$useraccounts."&amp;rcad=".$viewcustomer."&amp;user=".$username."'&gt;Send message&lt;/a&gt;";
            echo "&lt;tr&gt;";
            echo "&lt;td&gt;$userid&lt;/td&gt;";
            echo "&lt;td&gt;$username&lt;/td&gt;";
            echo "&lt;td&gt;$lname&lt;/td&gt;";
            echo "&lt;td&gt;$fname&lt;/td&gt;";
            echo "&lt;td&gt;$mi&lt;/td&gt;";
            echo "&lt;td&gt;$address&lt;/td&gt;";
            echo "&lt;td&gt;$contact&lt;/td&gt;";
            echo "&lt;td&gt;$month $day, $year&lt;/td&gt;";
            echo "&lt;td&gt;$dateregistered&lt;/td&gt;";
            echo "&lt;td&gt;$sendmessage&lt;/td&gt;";
            echo "&lt;/tr&gt;";
            echo "$table";

            if (isset($sendmessage)) {
                $getuser = $_GET['user'];
                if ($getuser == $username) {
                //start send message
                $touser = $username;
                $fromuser = $adminsess;
                $subject = $_POST['subject'];
                $message = $_POST['message'];
                $submit = $_POST['submit'];
                $date = date("Y-m-d"); 
                $rand = rand(98765432,23456789);

                $table = '&lt;center&gt;&lt;script type="text/javascript" src="/js/sendmessage.js"&gt;&lt;/script&gt;
                &lt;form action="cpanel.php?manage='.$useraccounts.'&amp;rcad='.$viewcustomer.'&amp;user='.$username.'&amp;send='.$one.'"  method="post" name="sendpm" onsubmit="return valid()"&gt;
                &lt;table&gt;
                &lt;tr&gt;
                &lt;td&gt;
                To:
                &lt;/td&gt;
                &lt;td&gt;
                '.$touser.'
                &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                &lt;td&gt;
                Subject:
                &lt;/td&gt;
                &lt;td&gt;
                &lt;input type="text" name="subject" id="subj1" /&gt;
                &lt;/td&gt;
                &lt;/tr&gt;    
                &lt;tr&gt;
                &lt;td&gt;
                Message:
                &lt;/td&gt;
                &lt;td&gt;
                &lt;textarea name="message" cols="60" rows="10" id="mes1"&gt;&lt;/textarea&gt;
                &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                &lt;td colspan="2"&gt;
                &lt;input type="submit" name = "submit" value="Submit" /&gt;
                &lt;/td&gt;
                &lt;/tr&gt;
                &lt;/table&gt;
                &lt;/form&gt;&lt;/center&gt;';
                        if (isset($submit))
                        {

                            $send = $_GET['send'];
                            if ($send == $one) {


                            include "maildbconnect.php";
                            $query = mysql_query("INSERT INTO mailtbl_admin VALUES ('', '$touser', '$fromuser', '$subject',
                            '$message', '0', '0', '1', '$date', '$rand')");
                            echo "Message successfully sent."; 
                            } 
                        }
                }//end send message
            }//end $getuser


            }

        }
</code></pre>

<p>The form for sending a message ($table) doesn't appear after clicking the link ($sendmessage) on a certain search result. After clicking the link, i'm prompted to an empty table (table not inside the while loop) but the $_GET function is working. Can anyone tell me how to fix this? thanks a lot</p>
