This "Undefined variable" means that you are trying to use a variable before you have created it.
This will also throw the same error:
<?php
echo "Hello, my name is {$name}.";
To resolve it, just define the variable before its first use:
<?php
$name = 'Jon Doe';
echo "Hello, my name is {$name}.";
The "Undefined index" error means that you're trying to reference an element in an array (or an object with array accessibility) which doesn't exist.
This will have the same error:
<?php
$array = array('first_name' => 'Jon', 'last_name' => 'Doe', 'age' => 35);
echo "Hello, my full name is {$array['first_name']} {$array['middle_initial']} {$array['last_name']} and I'm {$array['age']} years old.";
If you do not need this error to show, you can either initialize the array with empty strings (or null) to prevent the error, or use the hush operator (the "@" symbol) to suppress the error:
<?php
// Initialize the array:
$array = array('first_name' => 'Jon', 'middle_initial' => '', 'last_name' => 'Doe', 'age' => 35);
// OR
// Use hush operator:
echo "Hello, my name is " . @$array['first_name'] . " " . @$array['middle_initial'] . " " . @$array['last_name'] . " and I'm " . @$array['age'] . " years old.";
Otherwise you will want to inspect the array with either [man]print_r[/man] or [man]var_dump[/man] to see the elements in the array and change your code accordingly.