我创建了一个表消息,该消息具有user_id,message_sender,message_receiver,message_receiver_id列

查询结果如下

第1行:2 abol Alang 3

第2行:2 abol mak 4

第3行:3 alang abol 2

第4行:3个malang mak 4

我要显示具有行1,3,4的Alang记录的所有查询。我设法仅显示第3,4行,但无法显示第1行。这是代码

<?php
    include("includes/connections.php");
    function displaymessagesprofile(){
        global $connect;
        global $user_id;

            $get_id      = $_GET['message_receiver_id'];
            $sql_message = "SELECT * FROM messages WHERE user_id='$user_id' OR message_receiver_id='$get_id'";
            $get_message = mysqli_query($connect, $sql_message);

            if($get_message && mysqli_num_rows($get_message) > 0 ){
                while($row_message = mysqli_fetch_array($get_message)){

                $user_id            = $row_message['user_id'];
                $message_sender     = $row_message['message_sender'];
                $message_receiver   = $row_message['message_receiver'];
                $message_receiver_id= $row_message['message_receiver_id'];

                        //to display message sent and received by the user logged in
                        echo    "<div id='message_wrap'>
                                    <p>$message_sender</p>
                                    <p>$message_receiver</p>
                                    <p>$message_receiver_id</p>
                                </div>
                                ";
                }
            mysqli_free_result($get_message);
            }
            else{
                echo "No message yet";
            }
    }
?>


错误显示如下:


  注意:未定义索引:message_receiver_id

最佳答案

$get_id      = $_GET['message_receiver_id'];

change to

$get_id      = isset($_REQUEST['message_receiver_id']) ? $_REQUEST['message_receiver_id'] : '';


您可能需要使用filter_var消毒

10-07 20:41