"First Name",
"last_name" => "Last Name",
"phone" => "Phone");
/* check each field for blank fields */
foreach ($_POST as $field => $value)
{
if ( $value == "" )
{
$blank_array[] = $field;
}
}
/* check format of phone number */
if(!ereg("^[0-9)( -]{7,20}(([xX]|(ext)|(ex))?[ -]?[0-9]{1,7})?$",$_POST['phone']))
{
$bad_format[] = "phone";
}
/* if any fields were not okay, display error message and form */
if (@sizeof($blank_array) > 0 or @sizeof($bad_format) > 0)
{
if (@sizeof($blank_array) > 0)
{
/* display message for missing information */
echo "You didn't fill in one or more required
fields. You must enter:
";
/* display list of missing information */
foreach($blank_array as $value)
{
echo " {$labels[$value]}
";
}
}
if (@sizeof($bad_format) > 0)
{
/* display message for bad phone number */
echo "Your phone number appears to be incorrect.
";
}
/* redisplay form */
echo "
";
echo "Please enter your phone number below.
";
echo "";
exit();
}
else //if data is okay
{
$good_data['phone'] = strip_tags(trim($_POST['phone']));
$good_data['phone'] = ereg_replace("[)( .-]","",$good_data['phone']);
$user="admin";
$host="localhost";
$password="";
$database = "MemberDirectory";
$cxn = mysql_connect($host,$user,$password)
or die ("Couldn't connect to server");
mysql_select_db($database);
$query = "UPDATE Phone SET phone='$good_data[phone]'
WHERE lastName='$_POST[last_name]'
AND firstName='$_POST[first_name]'";
$result = mysql_query($query)
or die ("Couldn't execute query: ".mysql_error($cxn));
if(mysql_affected_rows($cxn) > 0)
{
echo "The phone number for {$_POST['first_name']} {$_POST['last_name']}
has been updated
";
}
else
echo "No record updated";
}
?>