doushang2571 2015-09-23 13:09
浏览 59
已采纳

使php表单生成的变量在两个php文件中可用

I have a form, Form_hour.php, that is loaded into the browser, and allows a user to select an hour. The form sends the variable $hour, via action="get", to the file View_A.php which uses $hour to query a database, and then loads View_A.php into the browser window, showing data for the selected hour.

In View_A, there is a button allowing the user to switch to View_B. The idea is that when the user clicks on View_B, the file View_B.php loads in the browser. View_B.php, like View_A.php, queries the database using that same $hour.

So what I want is for the same user-selected variable $hour to be available to both View_A.php AND View_B.php. i.e., if the user selects 6 a.m., then I want View_A and View_B to show data for 6 a.m.

I thought that having Form_hour.php send $hour to the file common.php, and then include common.php in View_A.php and View_B.php would work. But I keep getting the error "Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4327 bytes)" in View_A.php.

Does anyone have any ideas what I'm doing wrong?

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • drl971115 2015-09-23 13:27
    关注

    If I'm not mistaken you could just do it like I wrote below.
    This will direct the user to a difrent page, but will do what you want.


    form_hour.php

    <form action="View_A.php" method="post">
         your code
    </form>
    

    View_A.php

    <?php
    $_POST['hour'] = $hour
    // query database and do something with it!
    ?>
    
    <form action="View_B.php" method="post">
         <input type="hidden" name="hour" value=<?php print('"'.$hour.'"'); ?>>
         <input type="submit" ..... >
    </from>
    

    Like you asked, If you want the form as a var.

    <?php
    $_POST['hour'] = $hour
    // query database and do something with it!
    
    $form = '<form action="View_B.php" method="post">
         <input type="hidden" name="hour" value="'.$hour.'">
         <input type="submit" ..... >
    </from>';
    
    //to show it just print/echo it.
    print($from);
    ?>
    

    View_B.php

    <?php
    $_POST['hour'] = $hour
    // query database and do something with it!
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?