"Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP
Asked 07 September, 2021
Viewed 567 times
  • 58
Votes

I'm running a PHP script and continue to receive errors like:


Notice: Undefined variable: my_variable_name in C:wampwwwmypathindex.php on line 10

Notice: Undefined index: my_index C:wampwwwmypathindex.php on line 11

Line 10 and 11 looks like this:

echo "My variable value is: " . $my_variable_name;
echo "My index value is: " . $my_array["my_index"];

What is the meaning of these error messages?

Why do they appear all of a sudden? I used to use this script for years and I've never had any problem.

How do I fix them?



This is a General Reference question for people to link to as duplicate, instead of having to explain the issue over and over again. I feel this is necessary because most real-world answers on this issue are very specific.

Related Meta discussion:

29 Answer