1

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'); 
?>
WestX64
  • 11
  • 1
  • PHP variables are case sensitive so all your `$_Session` uses will be returning `false` in the `isset()` calls – Phil Oct 25 '18 at 00:07
  • Thank you so much for this, I am kicking myself so hard right now! – WestX64 Oct 25 '18 at 00:14
  • If you're not already, I recommend using an IDE that can flag things like this for you. From memory, the Netbeans PHP IDE is pretty good and free. – Phil Oct 25 '18 at 00:15
  • 1
    Thanks for providing everything required in your question. Even though your problem was just a typo, I didn't have to ask a million questions to get to the root cause. Cheers! – Phil Oct 25 '18 at 00:22

0 Answers0