如何从另一个PHP文件获取PHP变量值?(How to get a PHP variable value from another PHP file?)

编程入门 行业动态 更新时间:2024-10-24 05:18:05
如何从另一个PHP文件获取PHP变量值?(How to get a PHP variable value from another PHP file?)

如何从另一个.php文件获取值帮助我解决这个问题:

<html> <head> </head> <body> <form name='answer' action="file2.php" method="post"> <input type="text" name="what"> <input type="submit" value="Login"> </form> <div><?php echo $answer; ?></div> </body> </html>

file2.php文件的代码如下:

<?php if ($_POST['what']==animal){ $answer="dog"; }else{ $answer= "not animal"; }

我想知道如何获得变量$ answer与按钮的值,然后我应该在该行放置什么:

how to take the value from another .php file help me fix this:

<html> <head> </head> <body> <form name='answer' action="file2.php" method="post"> <input type="text" name="what"> <input type="submit" value="Login"> </form> <div><?php echo $answer; ?></div> </body> </html>

And the code of file2.php file is as below:

<?php if ($_POST['what']==animal){ $answer="dog"; }else{ $answer= "not animal"; }

I would like to know how can I get the value of the variable $answer with button, then what should I put at the line :

最满意答案

只需使用requiere

<?php require 'file2.php'; ?>

Just use requiere

<?php require 'file2.php'; ?>

更多推荐

本文发布于:2023-08-01 02:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1352821.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   变量值   PHP   variable   file

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!