PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a script that generates html based on certain conditions being met, one of the types is a drop down list. I have been given this script below to generate the drop down, but the problem I am having relates to undefined indexes as indicated below:
$display .= "Please select rate type:"; **** Undefined index on '$display'
$display .= '<select size="1" name="test">';
foreach(array('Approximate Charge', 'Per Hour') as $value)
{
$selected = ($_POST['test'] == $value) ? ' selected="selected"' : ''; **** undefined index on 'test'
$display .= "<option value='$value'$selected>$value</option>\n";
}
$display .= '</select>';
echo $display;
When I enter a value in the drop down and hit submiot the page returns with these errors gone, I therefore tried to use isset on post but this then did not display the html above because nothing is intially set.
the ".=" operator requires the variable to exist and be initialized prior to it's evaluation. So you either need to change the first one to a normal assignment, or initialize the variable prior.
Do you understand any of what was fixed? I only ask because there is a strong likelihood that these same errors will come up again in later code of yours if you are not sure about what was handled here.