Hello,
I am trying to create a directory of information to be stored in an associative array as strings and I have been having a problem figuring out how to get multiple entries into the array. My entry form (an HTML page) does work and collects the information and sends it to a PHP script which stores it in an array as a string but I need to know how to reset the HTML entry form to add another entry and introduce that to the array as a second value. So far all I have been able to do is enter one set of data and store it into an array. Nevertheless I will show you my code and you can dissect it and make suggestions as to what I might be doing wrong here!!:icon_confused:
First I will show you the code for the HTML entry form:
<!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>
but as I stated this seems to be working and I simply need to know how to reset this form to gather another set of user data to continue.
This form sends the data to a separate PHP script to store it and eventually manipulate it with the following 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");
}
asort($output);
foreach($output as $directory){
echo "$directory";
}
?>
</body>
</html>
This does receive the form data and stores it into an array correctly but I need to know how to enter more data from the HTML page because I need a directory with multiple entries that can be manipulated later. :icon_eek:
My project is supposed to create an entry form for a web site that is members only and store the individual data into an associative array for future viewing and manipulations after validating all entry fields.:icon_question:
Please if anyone can I would greatly appreciate any advice on how to do what I am attempting!!:icon_biggrin: