So I have been working at this for a few days now trying to figure this out and have Googled the heck out of it with no luck. I have an HTML form that is posting information to a PHP document. I'm trying to grab that information and push it to session arrays and then send the user back to the HTML form. I'm trying to make it so that each time the user submits the form, the new information is added to the session arrays. However, it seems like the arrays are being reset with each new submission as only the last entry is reflected when I print_r the session, or sometimes nothing appears in the array at all. I have tried with different browsers and on different machines too. Here is the PHP code:
<?php
session_start();
if (!isset($_Session['county'])) {
$_SESSION['county'] = array();
}
if (!isset($_Session['state'])) {
$_SESSION['state'] = array();
}
if (!isset($_Session['householdNumber'])) {
$_SESSION['householdNumber'] = array();
}
if (!isset($_Session['householdIncome'])) {
$_SESSION['householdIncome'] = array();
}
$dtmDateOfSurvey = $_POST["dtmDateOfSurvey"];
$strCountyAndState = $_POST["strCountyAndState"];
$intNumberInHousehold = $_POST["intNumberInHousehold"];
$dblHouseholdYearlyIncome = $_POST["dblHouseholdYearlyIncome"];
$arrCountyState = explode(',', $strCountyAndState);
$strCounty = $arrCountyState[0];
$strState = $arrCountyState[1];
array_push($_SESSION['county'],$strCounty);
array_push($_SESSION['state'],$strState);
array_push($_SESSION['householdNumber'],$intNumberInHousehold);
array_push($_SESSION['householdIncome'],$dblHouseholdYearlyIncome);
header('Location: index.html');
?>