Confusing directory PHP

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
Forum Newbie
Posts: 1
Joined: Wed Jan 05, 2011 7:35 pm

Confusing directory PHP

Post by zlloyd1 »

This is code for my HTML page which is supposed to gather data from a visitor for a directory and send it to a PHP file for storage and manipulation:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="">
<title>Directory Listing</title>
<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" />&nbsp;
&nbsp;<input type="submit" name="submit" value="send form" />
This entry form does work as far as collecting the data and sending it to the PHP file but i need to reset it after each set of data is entered and that is my issue. The data entered here is stored as a string into an array of strings which I need to be able to manipulate and sort but no matter what I try I can only get one set of data to be entered and so the array only has one string in it. :dubious: The array always has whatever was the last set of data entered and nothing else and I need advice how to reset the HTML page to receive multiple data sets so that I can fill up my array. :banghead:
Anyway here is the PHP file code:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="">
error_reporting(E_ALL & ~E_NOTICE);
$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";
function wordCheck($data, $fieldName)
if (empty($data))
DisplayError($fieldName, "Please enter $fieldName");
$retval = "";
return $data;
if ($errorCount>0) 
echo "Please re-enter data.<br />\n";
$filename = "file.txt";
$fp = fopen($filename, "w+");
$output =array("$lname , $fname ,  $addr ,  $cty ,  $stat , $zip , $acode - $phone");
foreach($output as $directory){

  echo "$directory";
and as I stated this does also work in collecting the data from the HTML file and placing it into an array as a string but I cannot get any more strings from the HTML page into this file because I do not know how to reset it properly. :cry: That is what I really need is for someone to tell me how to collect more data from different users and insert all of it into a single array from processing. I will await your reply!! :bow:
Forum Commoner
Posts: 91
Joined: Sat Oct 16, 2010 4:30 pm
Location: Lithuania, Vilnius

Re: Confusing directory PHP

Post by jankidudel »

Do you want to collect your data as in this example : ?
$zip = array("zip1", "zip2", "zip3") ???
$email = array('email1", "email2", "email3") ???

There are 2 possibilities to do this:

1.If you don't understand how to work with database, you can just put all your zip's in 1 file, all your emails in 2 file and so on. These files will be like temporary storages, then you can retrieve all your distinct values in distinct arrays and work with them.

.2 but if you can do things with database, it will be even easier to retrieve all emails, zips, ......
Post Reply