Hello, I am supposed to alphabetize an array created from an HTML entry form. The array is supposed to take the information entered and place it into individual strings which will them be placed into an array which I must then alphabetize by last names. This is the code for my HTML entry page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Directory Listing</title>
</head>
<body>
<h3>Please enter personal information</h3>
<form action="Directory2b.php" method="post">
<p>Lastname: <input type="text" name="lastname"></p>
<p>Firstname: <input type="text" name="firstname"></p>
<p>Address: <input type="text" name="address"</p>
<p>City: <input type="text" name="city"</p>
<p>State: <input type="text" name="state"></p>
<p>Zipcode: <input type="text" name="zipcode"></p>
<p>Areacode: <input type="text" name="areacode"></p>
<p>Telephone: <input type="text" name="telephone"></p>
<h3>please enter dash in telephone number for our records.</h3>
<input type="reset" value="Clear Form" />
<input type="submit" name="submit" value="send form" />
</form>
</body>
</html>
and this works fine, the data is entered and transferred to the PHP file for processing. This is the PHP file code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>Directory</title>
<body>
<?php
error_reporting(E_ALL & ~E_NOTICE);
$lname=$_POST["lastname"];
$fname=$_POST["firstname"];
$addr=$_POST["address"];
$cty=$_POST["city"];
$stat=$_POST["state"];
$zip=$_POST["zipcode"];
$acode=$_POST["areacode"];
$phone=$_POST["telephone"];
$words[] = wordCheck($lname, "lastname");
$words[] = wordCheck($fname, "firstname");
$words[] = wordCheck($addr, "address");
$words[] = wordCheck($cty, "city");
$words[] = wordCheck($stat, "state");
$words[] = wordCheck($zip, "zipcode");
$words[] = wordCheck($acode, "areacode");
$words[] = wordCheck($phone, "telephone");
global $errorCount;
function DisplayError($fieldName, $errorMsg)
{
echo "Error for \"$fieldName\": $errorMsg<br \>\n";
++$errorCount;
}
function wordCheck($data, $fieldName)
{
if (empty($data))
{
DisplayError($fieldName, "Please enter $fieldName");
$retval = "";
}
else
{
return $data;
}
}
if ($errorCount>0)
{
echo "Please re-enter data.<br />\n";
}
else
$filename = "file.txt";
$fp = fopen($filename, "w+");
$output =array("$lname, $fname , $addr, $cty, $stat, $zip, $acode, $phone");
ksort($output);
foreach ($output as $directory)
{
echo "$directory";
}
?>
</body>
</html>
and this is where I am having issues. You see I would like to introduce both blank spaces in between certain fields and place a - between the areacode and the phone number. Unfortunately every time I try to add anything to the array I get unpredictable results when printing out the results. :icon_mad:
Anyone who could point me in the right direction would be a savior and I would be eternally grateful.:icon_biggrin:
Also I would appreciate any suggestions of how to alphabetize the entered data once it is formatted correctly. I am fairly new to PHP scripting.:icon_redface:
I will await any replies hopefully!!
Zack:icon_question: