Guides › HTML / PHP sites › Site down or error screens

PHP Warning: Undefined Variable, Undefined Index or Undefined Array Key

These warnings mean the code read a value that was not set. Fix by checking before use.

Reference guide. This guide is written from established practice and the official documentation of the tools involved. We have not yet tested every step on a live demo site. Back up your site before you change anything.

Meaning

PHP is telling you the variable or array item does not exist. Newer PHP versions show these more clearly.

Fix

  1. Find the file and line. See seeing PHP errors.
  2. Make sure the variable is assigned before use, in all code paths.
  3. For arrays, check with isset() or use the null coalescing operator ($_POST['name'] ?? '').
  4. For form fields, remember unchecked checkboxes are not sent.
  5. Keep display_errors off on live sites and log errors instead.

After upgrading PHP

Old code may now show more warnings. See Site Broke After a PHP Version Upgrade: Deprecated and Removed Functions.

Related guides

Did this solve it? If not, email hello@sitefixlab.org with the exact error text and we will look into it. Try the problem finder.

Last updated 2026-11-21.