在两个php文件中使php表单生成的变量可用 [英] make php form-generated variable available in two php files

查看:133
本文介绍了在两个php文件中使php表单生成的变量可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单, Form_hour.php ,它被加载到浏览器中,并允许用户选择一个小时。表单通过 action =get将变量 $小时发送到文件 View_A.php 它使用 $小时查询数据库,然后加载 View_A.php 进入浏览器窗口,显示所选小时的数据。

在View_A中,有一个按钮允许用户切换到View_B。这个想法是,当用户点击View_B时,文件 View_B.php 会在浏览器中加载。 View_B.php ,例如 View_A.php ,使用相同的 $ hour



所以我想要的是用户选择的变量 $小时到可用于 View_A.php AND View_B.php 。即如果用户选择了6点,那么我希望View_A和View_B显示上午6点的数据。

/ code>发送 $小时到文件 common.php ,然后包含 common.php View_A.php View_B.php 中工作。但是我一直在 View_A.php 中收到错误致命错误:134217728个字节的内存大小已耗尽(尝试分配4327个字节)



有没有人有任何想法我做错了?



预先致谢!

解决方案

如果我没有弄错,你可以像下面写的那样做。

这将引导用户一个不同的页面,但会做你想做的。





form_hour.php

 < form action =View_A.phpmethod =post> 
您的代码
< / form>

View_A.php

 <?php 
$ _POST ['hour'] = $ hour
//查询数据库并使用它进行操作!
?>

< form action =View_B.phpmethod =post>
< input type =hiddenname =hourvalue =<?php print('''。$ hour。''); ?>>
< input type =submit.....>
< / from>

就像你问的那样,如果你想将表单作为var。

$ $ p $ <?php
$ _POST ['hour'] = $ hour
/ /查询数据库并用它做一些事情!

$ form ='< form action =View_B.phpmethod =post>
< input type =hiddenname =hourvalue ='。$ hour。'>
< input type =submit.....>
< / from>';

//显示它只是打印/回显它。
print($ from);
?>

View_B.php

 <?php 
$ _POST ['hour'] = $ hour
//查询数据库并使用它进行操作!
?>


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!

解决方案

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!
?>

这篇关于在两个php文件中使php表单生成的变量可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆