I'm a beginner in PHP.
I'm learning PHP from an ebook and as well following the exercises. Along the line, I got stuck with this example. see code below.
<html>
<head><title>Empty fields</title></head>
<body>
<?php
error_reporting(E_ALL);
// set up array with all fields
$labels = array("first_name" => "First Name", "middle_name" => "Middle Name", "last_name" => "Last Name",
"phone" => "Phone");
// check each field except middle name for blanks
foreach($_POST as $field => $value)
{
if($field != "middle_name")
{
if($value == "")
{
$blank_array[] = $field;
}
}
}
// if any fields were blank, display error message and redisplay form
if(count($blank_array) > 0)
{
echo "<b>You didn't ill in one or more required fields. You must enter:</b><br>";
// display list of missing information
foreach($blank_array as $value)
{
echo " {$labels[$value]}<br>";
}
// redisplay form
echo "<p>";
echo "<form action='$_SERVER[PHP_SELF]' method='POST'>
<table>";
foreach($labels as $field => $label)
{
$good_data[$field] = strip_tags(trim($_POST[$field]));
echo "<tr>
<td style='text-align': right; font-weight:bold'>{$labels[$field]}</td>
<td><input type='text' name='$field' size='45' maxlength='65' value='$good_data[$field]'></td>
</tr>";
}
echo "<tr>
<td colspan'2' style='text-align: center>
<input type='submit' value='Submit Name and Phone Number'>";
echo "</td></tr></table>
</form>";
exit();
}
echo "All required fields contain information";
?>
</body></html>
The code is trying to check the required fields for blank from an html form, then redisplay the form with the error noticed. But on the PHP page, I recieve an error like
"Notice: Undefined variable: blank_array in D:\wamp\wamp\www\myProjects\tryCode\checkBlank.php on line 23
All required fileds contain information".
Please help me with this code, I have tried all I could do.