PHP Developers Network
http://forums.devnetwork.net/

Confusing directory PHP
http://forums.devnetwork.net/viewtopic.php?f=50&t=126365
Page 1 of 1

Author:  zlloyd1 [ Wed Jan 05, 2011 8:47 pm ]
Post subject:  Confusing directory PHP

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"
"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" />&nbsp;
&nbsp;<input type="submit" name="submit" value="send form" />
</form>
</body>
</html>
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:
Syntax: [ Download ] [ Hide ]
<!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");
}
asort($output);
foreach($output as $directory){

  echo "$directory";
}
?>
</body>
</html>
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:

Author:  jankidudel [ Wed Jan 05, 2011 8:58 pm ]
Post subject:  Re: Confusing directory PHP

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, ......

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/