在搜索表单中链接(在搜索查询的while循环上)

时间:2011-08-16 15:27:18

标签: php

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

        $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 = "<a href = 'cpanel.php?manage=".$useraccounts."&rcad=".$viewcustomer."&user=".$username."'>Send message</a>";
            echo "<tr>";
            echo "<td>$userid</td>";
            echo "<td>$username</td>";
            echo "<td>$lname</td>";
            echo "<td>$fname</td>";
            echo "<td>$mi</td>";
            echo "<td>$address</td>";
            echo "<td>$contact</td>";
            echo "<td>$month $day, $year</td>";
            echo "<td>$dateregistered</td>";
            echo "<td>$sendmessage</td>";
            echo "</tr>";
            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 = '<center><script type="text/javascript" src="/js/sendmessage.js"></script>
                <form action="cpanel.php?manage='.$useraccounts.'&rcad='.$viewcustomer.'&user='.$username.'&send='.$one.'"  method="post" name="sendpm" onsubmit="return valid()">
                <table>
                <tr>
                <td>
                To:
                </td>
                <td>
                '.$touser.'
                </td>
                </tr>
                <tr>
                <td>
                Subject:
                </td>
                <td>
                <input type="text" name="subject" id="subj1" />
                </td>
                </tr>    
                <tr>
                <td>
                Message:
                </td>
                <td>
                <textarea name="message" cols="60" rows="10" id="mes1"></textarea>
                </td>
                </tr>
                <tr>
                <td colspan="2">
                <input type="submit" name = "submit" value="Submit" />
                </td>
                </tr>
                </table>
                </form></center>';
                        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


            }

        }

单击特定搜索结果上的链接($ sendmessage)后,不会显示发送消息($ table)的表单。单击链接后,我被提示输入一个空表(不在while循环中的表),但$ _GET函数正在运行。谁能告诉我如何解决这个问题?非常感谢

2 个答案:

答案 0 :(得分:0)

点击链接后不会设置

$ submit。所以之后的任何代码:

if(isset($submit)) {

不会开枪。

答案 1 :(得分:0)

你对这张表格有很多错误。首先,您忘记了<tr>标记后的<td><table>

echo "<center><form name = 'searching' method='POST' action='cpanel.php?manage=".$useraccounts."&rcad=".$viewcustomer."'><table border = 1><tr><td colspan='10'>";
    echo "<select name = 'filter'>";
    echo "<option value ='username'>Username</option>";
    echo "<option value ='username'>Username</option>";
    echo "</select>";
    echo "  <input name='search' type='text' >   "; 
    echo "<input type='submit' name='submit' value='Search'> ";
    echo "<input type='submit' name='back' value='Back'><br><br>";
    echo "</td></tr>";

或者,您可以将<table>标记下方的开头<select>标记移动。

修复之后,尝试将插入值的逻辑移动到循环外的mailtbl_admin中。我猜你只是想要将消息发送给一个用户,所以只有把它移出循环才有意义。