doutan5844 2014-03-14 15:34
浏览 51
已采纳

用include标签传递变量php

I am attempting to pass a variable to a different php file, my code to get the variable is this,

<?php  
    global $changeDate;
    $changeDate = $_POST['editdate'];
    $results = "SELECT title, DATE(start) FROM rota WHERE DATE(start) = '$changeDate' ";
    $workingUser = mysql_query($results);   
    include 'phpfunctions/holddate.php';
?>

holddate.php is this,

<?php
    $holdingdate = 0; 
    $holdingdate = $changeDate;
?>

on execution I get an error saying $changeDate is an undefined variable in holddate.php, where is this going wrong? This includes the global setting recomended but still recieve same error.

  • 写回答

2条回答 默认 最新

  • doupo2157 2014-03-14 16:05
    关注

    You shouldnt have to use global attribute or sesions.
    Try turning errors on and see if you get any errors returned.

    error_reporting(E_ALL); 
    ini_set('display_errors', '1');
    

    From the DOCS

    When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward. However, all functions and classes defined in the included file have the global scope.

    I would try to stay away from creating global variables unless its absolutely necessary. Also since you already tried tht and it does not work there is another problem besides the variable scope.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化