通过HTML表单传递PHP变量值 [英] Pass a PHP variable value through an HTML form
问题描述
以html格式,我有一个变量$var = "some value";
.
In a html form I have a variable $var = "some value";
.
我想在表单发布后调用此变量.表单被发布在同一页面上.
I want to call this variable after the form posted. The form is posted on the same page.
我想在这里打电话
if (isset($_POST['save_exit']))
{
echo $var;
}
但是该变量未打印.我必须在哪里使用代码GLOBAL?
But the variable is not printing. Where I have to use the code GLOBAL ??
推荐答案
编辑:在您发表评论后,我了解到您希望通过表单传递变量.
After your comments, I understand that you want to pass variable through your form.
您可以使用隐藏字段执行此操作:
You can do this using hidden field:
<input type='hidden' name='var' value='<?php echo "$var";?>'/>
在PHP操作文件中:
<?php
if(isset($_POST['var'])) $var=$_POST['var'];
?>
或使用会话: 在您的第一页:
Or using sessions: In your first page:
$_SESSION['var']=$var;
start_session();
应该放在您的php页面的开头.
start_session();
should be placed at the beginning of your php page.
在PHP操作文件中:
if(isset($_SESSION['var'])) $var=$_SESSION['var'];
第一个答案:
您也可以使用$GLOBALS
:
if (isset($_POST['save_exit']))
{
echo $GLOBALS['var'];
}
检查此 文档 以获得更多信息信息.
Check this documentation for more informations.
这篇关于通过HTML表单传递PHP变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!