I have a project I am near completing except I cannot properly test it because the array uses sessions and is full of useless data now. I have an HTML entry form that feeds data to this PHP script:
<!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>
<a href="Lloyd_assignment4.html>Back to directory</a>
<?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 "Errors Please reenter data<br \>\n";
else{
session_start();
if(!isset($_SESSION['Sword']))
{
session_register();
$_SESSION['sword']=array();
}
$iterator=count($_SESSION['sword']);
$_SESSION['sword'][$iterator][] = wordCheck($lname , "lastname");
$_SESSION['sword'][$iterator][] = wordCheck($fname , "firstname");
$_SESSION['sword'][$iterator][] = wordCheck($addr , "address");
$_SESSION['Sword'][$iterator][] = wordCheck($cty , "city");
$_SESSION['Sword'][$iterator][] = wordCheck($stat , "state");
$_SESSION['Sword'][$iterator][] = wordCheck($zip , "zipcode");
$_SESSION['Sword'][$iterator][] = wordCheck($acode , "areacode");
$_SESSION['Sword'][$iterator][] = wordCheck($phone, "telephone");
asort($_SESSION);}
foreach($_SESSION as $directory){
print_r($directory);
}
?>
</body>
</html>
but unfortunately I am at a loss for how to use the echo command to read the data stored in the array to the screen without including the keys as with the print_r function. I need to read the data out as entries and not array values. If anyone could help me by showing me where and how to place the echo command in order to properly echo the array I would be eternally grateful!!:icon_smile:
Also if possible could you tell me where and how to place the unset() function to clear out the existing array values so that I can continue with testing??:icon_question: