Warning: Trying to access array offset on value of type null
I´m getting this warning in my ChatApp userlist. The ChatApp is made with php and mysql.
This is the line were the warning appears:
($outgoing_id == $row2['outgoing_msg_id']) ? $you = "You: " : $you = "";
This is the whole data.php file:
<?php
while($row = mysqli_fetch_assoc($sql)){
$sql2 = "SELECT * FROM messages WHERE (incoming_msg_id = {$row['unique_id']}
OR outgoing_msg_id = {$row['unique_id']}) AND (outgoing_msg_id = {$outgoing_id}
OR incoming_msg_id = {$outgoing_id}) ORDER BY msg_id DESC LIMIT 1";
$query2 = mysqli_query($conn, $sql2);
$row2 = mysqli_fetch_assoc($query2);
if(mysqli_num_rows($query2) > 0){
$result = $row2['msg'];
}else{
$result = "No messages avaiable";
}
(strlen($result) > 28) ? $msg = substr($result, 0, 28).'...' : $msg = $result;
($outgoing_id == $row2['outgoing_msg_id']) ? $you = "You: " : $you = "";
$output .= '<a href="chat.php?user_id='.$row['unique_id'].'">
<div class="content">
<img src="php/images/'. $row['img'] .'" alt="">
<div class="details">
<span>'. $row['fname'] . " " . $row['lname'] .'</span>
<p>'. $you . $msg .'</p>
</div>
</div>
<div class="status-dot"><i class="fas fa-circle"></i></div>
</a>';
}
?>
The whole ChatApp runs with XAMPP on localhost
We don´t know what we could do.
New contributor
FloTheProg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.