Jamilah Jamilah - 1 month ago 7
MySQL Question

How to select multiple column in PHP MySQLi

I created a table messages that have column user_id, message_sender, message_receiver, message_receiver_id

The result of query as below

Line 1 : 2 abol Alang 3

Line 2 : 2 abol mak 4

Line 3 : 3 alang abol 2

Line 4 : 3 alang mak 4

I want to display the all query that has Alang records which is Line 1,3,4. i managed to display line 3,4 only but cannot display line 1. here's the code

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


errors shows below :


Notice: Undefined index: message_receiver_id

Answer
$get_id      = $_GET['message_receiver_id'];

change to

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

You may need to use filter_var disinfection