开发者

Link (on a while loop on a search query) inside a search form

开发者 https://www.devze.com 2023-03-28 17:06 出处:网络
echo \"<center><form name = \'searching\' method=\'POST\' action=\'cpanel.php?manage=\".$useraccounts.\"&rcad=\".$viewcustomer.\"\'><table border = 1>\";
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


            }

        }

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


$submit wont be set when following the link. So any code after:

if(isset($submit)) {

Will not fire.


You've got a lot wrong with this form. First off, you forgot a <tr> and <td> after your <table> tag.

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

Alternatively you could move the opening <table> tag below the <select> tag.

After you fix that, try moving the logic where you insert the values into mailtbl_admin outside of the loop. I'm guessing you're only going to want to send the message to one user, so it only makes sense to move it out of the loop.

0

精彩评论

暂无评论...
验证码 换一张
取 消