I have to be doing something stupid here. Basically, I have a form a user fills out. It gets passed to the page that has code similar to what I've pasted below. What I don't understand is why the values for each item in the array $field_data are not evaluating as expected. The conditional statement is checking to see if any fields were left blank. No matter what I put into the fields before submitting the form, every value evaluates as blank. I even tried a forach loop and printed out the keys and values for each item in the array and they are definitely not blank. For example, the printed result was like:
Name=Bob
State=CA
So, I know the array contains string data (I double checked with gettype() and they are definitely string data), but when I try to compare the strings to anything, be it blank '' (two single quotes) or otherwise, the evaluations don't work as I expect.
Thanks for any help, I know I'm missing something obvious.
//requests all of the form variables from survey.php, once it's posted
//this has to be done before sending headers
$firstname = addslashes($_REQUEST['firstname']);
$lastname = addslashes($_REQUEST['lastname']);
$title = addslashes($_REQUEST['title']);
$company = addslashes($_REQUEST['company']);
$address1 = addslashes($_REQUEST['address1']);
$address2 = addslashes($_REQUEST['address2']);
$city = addslashes($_REQUEST['city']);
$state = addslashes($_REQUEST['state']);
$country = addslashes($_REQUEST['country']);
$zip = addslashes($_REQUEST['zip']);
$telephone = addslashes($_REQUEST['telephone']);
$email = addslashes($_REQUEST['email']);
//associates a key with each element of the form data so we can tell the user which (if any)
//fields were left blank on submission
$field_data = array('First Name' => $firstname, 'Last Name' => $lastname, 'Title' => $title, 'Company' =>
$company, 'Address Line 1' => $address1, 'City' => $city, 'State' => $state, 'Country' => $country, 'Zip/Country Code' =>
$zip, 'Telephone' => $telephone, 'Email' => $email);
$num_fields = count($field_data);
$error_list = array();
foreach ($field_data as $key=>$value)
if ($field_data[$value] == '') {
$error_list[] = 'You cannot leave the <font color="#FF0000">' . $key . '</font> field blank.';
}
if ($num_errors = (count($error_list)) == 0) {
echo 'There are no errors!';
}
else {
//give the user the error messages
}