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 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线