Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php wp\u会话变量被$\u POST覆盖_Php_Wordpress_Post_Session Variables - Fatal编程技术网

Php wp\u会话变量被$\u POST覆盖

Php wp\u会话变量被$\u POST覆盖,php,wordpress,post,session-variables,Php,Wordpress,Post,Session Variables,我正在尝试将一个表单发布到$wp_会话,该会话运行良好-但是,当我再次执行它时,它会覆盖我首先放置在那里的数组,我需要数组像收集/购物篮一样继续构建 我的表格: <form class="form1" method="post" action="" id="form1"> <fieldset> <ul> <label for="name">Exercise ID</label><span> &

我正在尝试将一个表单发布到$wp_会话,该会话运行良好-但是,当我再次执行它时,它会覆盖我首先放置在那里的数组,我需要数组像收集/购物篮一样继续构建

我的表格:

<form class="form1" method="post" action="" id="form1">
<fieldset>
<ul>
        <label for="name">Exercise ID</label><span>
        <input type="text" name="ExerciseID" placeholder="Exercise ID" class="required" role="input" aria-required="true"/></span>

        <label for="name">Exercise Reps</label><span>
        <input type="text" name="Sets" placeholder="Sets" class="required" role="input" aria-required="true"/></span>

        <label for="name">Exercise Reps</label><span>
        <input type="text" name="Reps" placeholder="Sets" class="required" role="input" aria-required="true"/></span>

        <input  class="submit .transparentButton" value="Next" type="submit" name="Submit"/> 

</ul>
<br/>
</fieldset>
</form>

    练习ID 运动重复 运动重复

而php:

<?php

global $wp_session;

if (isset($_POST['Submit'])) {
 $wp_session['collection'] = array($POST['ExerciseID'],$_POST['Sets'],$POST['Reps']);

}

print_r($wp_session);

?> 


非常感谢

要拥有篮子,您必须将产品添加到阵列中:

<?php

global $wp_session;

if (isset($_POST['Submit'])) {
 $wp_session['collection'][] = array($_POST['ExerciseID'],$_POST['Sets'],$_POST['Reps']);

}

print_r($wp_session);

?> 


您可能希望按ExerciseID组织数组,以便添加数量。我建议您创建一些对象,因为它们比数组更灵活

也许您正在寻找这样的方法:不是覆盖,而是在每次运行时向“会话变量”附加一个新条目:

<?php

global $wp_session;

if (isset($_POST['Submit'])) {
 $wp_session[]['collection'] = array($_POST['ExerciseID'],$_POST['Sets'],$_POST['Reps']);
}

print_r($wp_session);
?> 


注意作业左侧的附加
[]

首先,在
数组($POST['ExerciseID']、$\u POST['Sets']、$POST['Reps'])中缺少一些下划线。
尝试
数组($\u POST['ExerciseID']、$\u POST['Sets']、$\u POST['Reps'])
这些都是超全局的,其中99%需要是
$\u XXX
您遗漏了OP缺少两个下划线的部分。根据;-)OP的问题是变量被覆盖了,问题是如何将其添加为一个购物篮,而不是数据不正确(因为错误的值将以null形式出现)。我知道,我只是说问题中的“一”是缺少的两个下划线。通常,我们会指出这些错误。这对我来说仍然不起作用-它会不断覆盖创建的原始数组,给我
array(3){[“ExerciseID”]=>array(1){[0]=>string(2)“ID”}[“set”]=>array(1){[0]=>string(0)”“}[“Reps”=>array(1){[0]=>string(0)”}
根据您的判断,您也犯了同样的错误。是的,谢谢您的提醒。修正了。虽然这不是老年退休金计划的问题,不客气。你可能想在你的答案中加上这一点,说明缺少的两个下划线。我知道这一点,但指出错误是很好的。@Fred ii-OP声称他的代码在这方面起作用。所以我假设要么是他自己的打字错误(所以不是真正的问题),要么他确实有一个
$POST
变量,这是不可能的。使用
$POST
永远不会起作用。这是一个好主意。可能是因为只有一个结果通过了。不是OP在撒谎,就是打字错误,但我觉得这很难相信,因为缺少了两个下划线;或者偷懒地复制/粘贴。