0

I have been trying to get this directory to work properly and am about to tear my hair out!!:icon_mad:
This is my 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+");
$output1 =array($lname, $fname, $addr, $cty, $stat, $zip, $acode, $phone);
ksort($output1);
echo "<tr>";
echo "<td>$output1</td>";
?>
</body>
</html>

unfortunately all I get when I run this as output is the word array and nothing else!!:icon_sad:
If anyone can see what I am doing wrong here I would be eternally grateful!!
PLEASE HELP ME!!!!:icon_redface:

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by zlloyd1
0

Perhaps it would be easier if you stated what exactly you want from the code. I assume you want to do a print_r on the $output1?

From what I can glean, the $words array isn't being echoed/printed. I'm afraid I can't really follow your code - no indentations - it swims in front of my eyes. Is it that the wordcheck function always returns the same condition?

0

Perhaps it would be easier if you stated what exactly you want from the code. I assume you want to do a print_r on the $output1?

From what I can glean, the $words array isn't being echoed/printed. I'm afraid I can't really follow your code - no indentations - it swims in front of my eyes. Is it that the wordcheck function always returns the same condition?

Thanks for taking a look at my code and to answer your question the code is a part of a class project to create a directory of information entered from an HTML file which collects information entered into fields provided on the web page. This is that file but I don't think there is any issues with the html file because it runs and creates the entry fields correctly and then send the data to the php file I showed you and the problem seems to be getting the data received into an associative array to be alphabetized and printed out to the screen. The issue I am having is that when I got to echo the array all that is being shown on the screen is the word array. I know also that the data is being placed into the array because that was the first part of the assignment the week before and I got 100 on that one. So my problem seems to be sorting the array and reading it to the screen properly.

Here is the other file to collect data from the user:

<!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="Directory2.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>
<input type="reset" value="Clear Form" />&nbsp;
&nbsp;<input type="submit" name="submit" value="send form" />
</form>
</body>
</html>

but as I said this should be working exactly as needed. My problem is in the PHP file shown before.
If you can see what mistake I have made that would be crazy helpful and if not thanks for taking a look and responding!!:icon_biggrin:

0

You can't directly 'echo' an array, you can use print_r($array) to show the contents. If you want pretty output, use 'foreach(...)'. See the php manual.

0

You can't directly 'echo' an array, you can use print_r($array) to show the contents. If you want pretty output, use 'foreach(...)'. See the php manual.

Thank you again for taking the time to respond and I will look into finding a different method of printing out the results!!:icon_wink:

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.