On Thursday, February 28, 2002, at 07:42 PM, Jeff Sheltren wrote:
> If you are setting a variable inside of the if statements, and then > checking that variable later, then I would say you should either use an > else statement to give that variable a default value, or you should set > the variable to a default value before the if statements. Your code is > "legitimate", ie. there is no reason you *have* to have an else > statement. > I would have thought that if I set this variable at all, then I wouldn't be able to use the second part of the script ( if($variable)... ). I have posted a snippet of the code at the bottom, if you don't mind checking it out. It works fine -- but it seems strange not to have an 'else'. The bare bones of it is like so: if (bad user input) { $error = true; $error_message = $a; } elseif (different bad user input) { $error = true; $error_message = $b; } elseif (still different bad user input) { $error = true; $error_message = $c; } if ($error) { do some things and then echo $error_message; } else { present confirmation dialog } ---- Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] for ($i = 1; $i <= $_POST['numfiles']; $i++) { // check text box for filename - no danger characters! if (preg_match("/[<>\"'\\/:]/", $_POST["filename{$i}"])) { $input_error_confirm = true; $error_message = $filename_is_invalid; $problem_file_number = $i; $problem_file_name = htmlspecialchars($_POST["filename${i}"]); // check text boxes for filesize, width, and height, must be of form 0000.00 } elseif ( !preg_match("/^\d{1,4}\.?\d{0,2}$/", $_POST["filesize${i}"]) || !preg_match("/^\d{1,4}\.?\d{0,2}$/", $_POST["width${i}"]) || !preg_match("/^\d{1,4}\.?\d{0,2}$/", $_POST["height${i}"]) || !preg_match("/^\d{1,4}$/", $_POST["resolution{$i}"]) ) { $input_error_confirm = true; $error_message = $filenum_is_invalid; $problem_file_number = $i; $problem_file_name = htmlspecialchars($_POST["filename${i}"]); // check text boxes to make sure that the default values (0.00) are not left unchanged } elseif ( (float) $_POST["filesize{$i}"] < 0.01 || (float) $_POST["width{$i}"] < 0.01 || (float) $_POST["height{$i}"] < 0.01 || (int) $_POST["resolution{$i}"] < 1 ) { $input_error_confirm = true; $error_message = $filenum_is_zero; $problem_file_number = $i; $problem_file_name = htmlspecialchars($_POST["filename{$i}"]); } elseif ($_POST["format{$i}"] == 0) { $input_error_confirm = true; $error_message = $no_format_specified; $problem_file_number = $i; $problem_file_name = htmlspecialchars($_POST["filename{$i}"]); } } // if errors in text inputs, error messages must be returned from this function if ($input_error_confirm) { $data_to_return = " <p class=\"warning\">Unfortunately, there was an error in your data, in file number <b class=\"label\">${problem_file_number} (" . stripslashes(${problem_file_name}) . ").</b></p> <p class=\"warning\">$error_message</p>\n"; $data_to_return .= addrecord_form($_POST['numfiles']); // otherwise text inputs are fine, display them to the user for confirmation } else { -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php