简体   繁体   English

在页面之间使用$ _POST方法

[英]Using the $_POST method between pages

I have three separate PHP pages. 我有三个单独的PHP页面。 On the first page, I pull information out of my database using the 'keywords' column, which I turn into checkboxes: 在第一页上,我使用'keywords'列从我的数据库中提取信息,我将其转为复选框:

$i=0;
foreach(explode(',', $keywords) as $keyword) {
    if($keyword != ""){
        $keyword = trim($keyword);
        $chkname = "checkbox{$i}";
        $i = $i+1;
        echo '<input type="checkbox" name="chkboxes[]" value="'.$keyword.'" id="chk_'.$keyword.'" />
                <label for="chk_'.$keyword.'">'.$keyword.'</label>'."<br />";

Then I pass this information into the second PHP script, which displays the checkboxes that a user actually checkmarks: 然后我将这些信息传递给第二个PHP脚本,该脚本显示用户实际选中标记的复选框:

if(isset($_POST['chkboxes'])) {
  foreach($_POST['chkboxes'] as $chkbox) {
        echo '- '.$chkbox."<br />";

On the third PHP script, I want to grab the checkboxes that the user has checkmarked, and echo them out. 在第三个PHP脚本中,我想获取用户已勾选的复选框,并将其回显。 For some reason I can't figure out, I can't grab the checkboxes that were checked. 出于某种原因,我无法弄清楚,我无法抓住已检查的复选框。 I've tried adding a hidden input field on the second php page, 我试过在第二个php页面上添加一个隐藏的输入字段,

if(isset($_POST['chkboxes'])) {
  foreach($_POST['chkboxes'] as $chkbox) {
        echo '- '.$chkbox."<br />";
        '<input type="hidden" name="options[]" id="options" value=" ' . $chkbox . '"/>';
  }

and on the thrid PHP script used: 并在使用的第三个PHP脚本上:

if(isset($_POST['options'])){
    $options = $_POST['options'];
}

I don't know where to go from here. 我不知道从哪里开始。 ANY help would be appreciated and I will select the correct answer. 任何帮助将不胜感激,我将选择正确的答案。 for now, on the third php page, I've been using print_r($_POST); 现在,在第三个php页面上,我一直在使用print_r($_POST); to see what happens. 看看会发生什么。 Everything works, except it's not posting the checked checkboxes. 一切正常,除了它没有发布选中的复选框。

You can use sessions in this case. 在这种情况下,您可以使用会话。 See: http://php.net/manual/en/book.session.php 见: http//php.net/manual/en/book.session.php

Btw: Did you submit your hidden inputs? 顺便说一下:你提交了隐藏的输入吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM