Welcome to the forums.
First off, in the future, please use this forum's [noparse]
...
[/noparse] tags around your code samples. (I've added them to your post -- see how pretty? 🙂 )
The first thing I noticed in the code is at line 59, where you have a lonely { that I'm guessing should be a }. Even after changing that and running the code through my "beautifier", it still does not balance out, however (see below). Hopefully upon looking at it you can decide what's missing (since presumably you know better than I what you want it to do. 😉 )
<?php
/* Program name: formvalidate.php
* Description: Program checks all the form fields for
* invalide content
*/
foreach($_POST as $field => $value) {
if (empty($value)) {
if ($field != "male") {
$blank_array[] = $field;
} else {
$good_data[$field] = strip_tags(trim($value));
}
}
if (@sizeof($blank_array) > 0) {
$message = "<p style='color: red; margin-bottom: 0;font-weight: bold'>
You didn't fill in one or more required fields.
You must enter:
<ul style='color: red; margin-top: 0;
list-style: none' >";
foreach($blank_array as $value) {
$message.= "<li>$value</li>";
}
$message.= "</ul>";
echo $message; {
extract($good_data);
include ("hwformfinal.inc");
exit();
}
foreach($_POST as $field => $value) {
if (!empty($value)) {
$last_name = "/^[A-Za-z' -]{1,50}$/";
$first_name = "/^[A-Za-z' -]{1,50}$/";
$email = "\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b}";
$phone = "/^[0-9)(xX -]{7,20}$/";
$order_date = "(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])";
$address = "^[0-9)( A-Za-z-]{7,20}";
$city = "[A-Za-z ] {50}";
$state = "/A-Za-z {2}/";
$radio = "/(male|female)/";
}
if (!preg_match($last_name, $value)) {
$error_array[] = "$value is not a valid name";
}
if (!preg_match($first_name, $value)) {
$error_array[] = "$value is not a valid name";
}
if (!preg_match($email, $value)) {
$error_array[] = "$value is not a valid email";
}
}
if (preg_match("/phone/i", $field)) {
if (!preg_match($phone_patt, $value)) {
$error_array[] = "$value is not a valid phone number";
}
} // endif phone format check
if (preg_match("/status/i", $field)) {
if (!preg_match($radio, $value)) {
$error_array[] = "$value is not a valid status";
}
$clean_data[$field] = strip_tags(trim($value));
}
if (@sizeof($error_array) > 0) {
$message = "<ul style='color: red; list-style: none' >";
foreach($error_array as $value) {
$message.= "<li>$value</li>";
}
$message.= "</ul>";
echo $message;
extract($clean_data);
include ("form_test3.inc");
exit();
} else {
echo "Data is all okay";
}
?>