我在以下代码中遇到所有类型的错误。我想从表单中发布数据并存储在$ _SESSION数组中以供将来处理
非法字符串偏移量'SurveyDate'
非法字符串偏移“收入”
<input class="formFields" type="date" id="txtDateOfSurvey" name="mycensus[0][SurveyDate]"
<input class="formFields" type="numeric" id="txtIncome" name="mycensus[0][Income]"
<?php
session_start();
if( !isset($_SESSION['mycart2']))
{
$_SESSION['mycart2'] = array();
}
$_SESSION['mycart2'] = array_merge($_SESSION['mycart'], $_POST['mycensus']);
foreach($_SESSION['mycart2'] as $v)
{
echo $v['SurveyDate'] . ' was born on ' . $v['Income'] . '<br>';
}
?>
我希望数组mycart2包含我在表单上输入的所有条目。
答案 0 :(得分:0)
<?php
session_start();
if(is_array(mycensus)){
$survey_date = mycensus[0]['SurveyDate'];
$Income = mycensus[0]['Income'];
}
?>
<input class="formFields" type="date" id="txtDateOfSurvey" name="survey_date" value="<?php echo $survey_date; ?>">
<input class="formFields" type="numeric" id="txtIncome" name="income" value="<?php echo $Income; ?>">
<?Php
if( !isset($_SESSION['mycart2']))
{
$_SESSION['mycart2'] = array();
}
$_SESSION['mycart2'] = array_merge($_SESSION['mycart'], $_POST['mycensus']);
foreach($_SESSION['mycart2'] as $v)
{
echo $v['SurveyDate'] . ' was born on ' . $v['Income'] . '<br>';
}
?>