0

I am getting following error on line 42 of my code. But strange thing is I am already checking for null and the actual error seems to be happening on line 44. How to fix this issue?

Error

Uncaught ErrorException: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/mysite/mypage.php:42

Code

while($row3 = mysqli_fetch_assoc($result3))
{
   $emailbody .= "<b>Keyword:</b> ". htmlspecialchars($row2["keyword"]) ."<br>";

   if(!is_null($row3["summary"]))     //line 42
   {
      $emailbody .= "<b>Summary:</b> ". htmlspecialchars($row3["summary"]) ."<br>";
   }
}
2
  • 1
    You don't check for $row2["keyword"] Commented Dec 16, 2023 at 10:37
  • How can it report that on line 42 when you indicate that line 42 doesn't call htmlspecialchars? Commented Dec 16, 2023 at 11:02

1 Answer 1

0

Since you're checking for nulls on the second call, the error must be coming from the first one: htmlspecialchars($row2["keyword"]). Add a null-check on that too, and you should be OK.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.