dongyanggan3025 2013-12-25 05:42
浏览 36
已采纳

错误信息注意:php中包含函数的未定义变量[关闭]

I have too separate PHP files:

  1. add-new-module.php
  2. _add-new-module.php

I' am using the function require_once _add-new-module.php in the add-new-module.php at the very top of the page. I have initialized the variable $msg into _add-new-module.php for some reason its still showing up error message as:

Notice: Undefined variable: msg in xxxxxxxxxxx/add-new-module.php on line 2

When echoing the variable $msg in _add-new-module.php it WORKS but when I try to echo the variable $msg in add-new-module.php it gives me above error. When I used islet on the variable $msg well it hides error message but doesn't show anything on the page.

I have also replaced include with include_once, require_once and require. Still no luck. I have also used global $msg hides the error message but doesn't seems to display the result.

  • 写回答

2条回答 默认 最新

  • dongtan3306 2013-12-25 05:54
    关注

    You can use global $msg; in add-new-module.php, just write it before echo $msg;

     global $msg;
     echo $msg; 
    

    if not working To Enable Global Variables Register_globals In PHP APACHE Server Php.ini

    register_globals = On

    if you want to turn it on within your page you can put this code at the begining of your code:

    ini_set('register_globals', true);

    otherwise enable register_globals via .htaccess:

    1. Create an .htaccess in your virtual host's root directory
    2. put the following code in it:

      //Override PHP settings. The first IfModule is //for Apache 1.3, the second for Apache 2.

       <IfModule mod_php4.c>
           php_value register_globals 1
       </IfModule>
      
       <IfModule sapi_apache2.c>
           php_value register_globals 1
       </IfModule>
      
         php_flag register_globals 1
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?