php - PHP会话数组在页面之间丢失
问题描述
因此,我已经为此工作了几天,现在试图弄清楚这一点,并在没有运气的情况下用谷歌搜索了它。我有一个将信息发布到 PHP 文档的 HTML 表单。我正在尝试获取该信息并将其推送到会话数组,然后将用户发送回 HTML 表单。我正在尝试使每次用户提交表单时,都会将新信息添加到会话数组中。但是,似乎每次新提交都会重置数组,因为当我 print_r 会话时仅反映最后一个条目,或者有时数组中根本没有出现任何内容。我也尝试过使用不同的浏览器和不同的机器。这是PHP代码:
<?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');
?>
解决方案
推荐阅读
- reactjs - schedules[0].timings[0].startTime 必须是 `string` 类型,但最终值为:`null` - 当字段为空时获取此值
- wpf - 如何在运行时创建不同的设置集?
- typescript - 在打字稿中的变量上使用扩展
- flutter - 如何在不使用字符串拆分的情况下在颤动中读取 V 卡文件(联系电话、姓名等)
- c# - 以 C# 窗口形式显示 WebCam 的视频帧
- java - 处理 DefaultHandlerExceptionResolver:org.springframework.http.converter.HttpMessageNotReadableException:JSON 解析错误:意外字符
- .net - 在发布者端为 MassTransit 在 SimpleInjector 中建立队列
- php - 需要对 api 响应 codeigniter 进行一些操作
- java - android.content.res.Resources$NotFoundException · 字符串资源 ID #
- php - 如果在课堂调用中的陈述