Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts

    Variable/Array not taking in another folder

    Hey all... Been a while since I've been here! G'day to all!

    Okay - so my issue is:

    PHP Code:
    <?
    session_start
    ();

    // index.php

    include('includes/actions.php');

    /*
     Some HTML here!!!!
    */
    echo $SET['content'];
    ?>
    PHP Code:
    <?
    // includes/actions.php

    switch($_GET['action']){
        case 
    "register":
            
    // module
            
    $SET['module'] = "register.php";
            
    // title
            
    $SET['title'] = "Register New Account";
            break;
        default:
            
    // module
            
    $SET['module'] = "main.php";
            
    // title
            
    $SET['title'] = "Home";
            break;
    // switch

    include($URL.'/actions/'.$SET['module']);
    ?>
    For this example I'll use "register" as the $_GET['action']:

    PHP Code:
    <?

    // actions/register.php 

    $SET['content'] = "All my content here (just to keep it short!)";

    ?>
    My problem being that it is not showing up via the index.php page. If I put on register.php "echo $SET['content'];" it works fine - but I can't do this as my $SET['content'] should actually appear under the html not above it.

    Any ideas why it would not be reading the value of the variable?

    Thanks in advance!

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    An issue of scope, perhaps?

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,038
    Thanks
    2
    Thanked 316 Times in 308 Posts
    it is not showing up via the index.php page. If I put on register.php
    If the code you posted is for two or more separate pages (it is not clear from your post what or where each piece of code is located) $SET['anything'] won't persist between pages. All general purpose variables are destroyed when code execution ends on any page.

    You have a session_start() statement, are you trying to use session variables to pass information between pages? If so, you need to use the $_SESSION[] array instead.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    Quote Originally Posted by Fumigator View Post
    An issue of scope, perhaps?
    Sorry - that made no sense to me! lol.. Scope?

    Quote Originally Posted by CFMaBiSmAd View Post
    If the code you posted is for two or more separate pages (it is not clear from your post what or where each piece of code is located) $SET['anything'] won't persist between pages. All general purpose variables are destroyed when code execution ends on any page.

    You have a session_start() statement, are you trying to use session variables to pass information between pages? If so, you need to use the $_SESSION[] array instead.
    At the top of each code it states which page the code is in:

    // index.php
    // includes/actions.php
    AND
    // actions/register.php

    And no, not trying to use session variables to pass the information.

    The index page includes "includes/actions.php" and this page includes "actions/register.php"

    In many situations before I have passed a variable from one page to another when "include()"d.. So not sure why it wouldn't work now.

    Any help appreciated!

  • #5
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Quote Originally Posted by Taylor_1978 View Post
    Sorry - that made no sense to me! lol.. Scope?
    http://php.net/variables.scope

    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #6
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    Thanks! But on quick glance of this, it is referring to variables set in functions, however no functions are being used as yet. Or am I missing something?

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,038
    Thanks
    2
    Thanked 316 Times in 308 Posts
    One ore more of your include()'s are probably failing (I don't see where $URL is being set). Either check your web server log for errors and/or put the following two lines in after your first opening <?php tag -
    PHP Code:
    ini_set ("display_errors""1");
    error_reporting(E_ALL); 
    Changing your include() statement into require() statements will keep your code from blindly executing if the require() fails.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #8
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    Ok - did all that and this is what I'm getting:

    Notice: Undefined variable: content in /home/goto/public_html/index.php on line 274

    Line 274 is <?=$SET['content'];?>

    Taking in what you said about maybe one of the includes isn't working, at the top of actions/register.php I added:

    echo "hi";

    The "hi" displayed at the top of the index page, which obviously indicates that it is including the page.

    I tried changing all my includes to require, however this also did not work.

    Oh and $URL is set in the includes/config.php page which is actually listed in the index.php, include('includes/congig.php'); but I left that part out in my example.

  • #9
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    $SET['content'] is not set

  • #10
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    But it is set lol... Well, I'm pretty sure it is hehe. In register.php I have:

    $SET['content'] = "html code";

    Just to make things nice and simple, I even changed all the HTML code (incase some form of error was occurring, to $SET['content'] = "hi"; - And still the same error

  • #11
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,038
    Thanks
    2
    Thanked 316 Times in 308 Posts
    Either the assignment statement $SET['content'] = ... in register.php is not being executed (contained in conditional logic or a return() statement is being executed before it is reached) or at some point after the assignment statement it is being unset(), since it does not exist at the point it is being echoed.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #12
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    Wouldn't I have to do an unset() in order for that to happen. And there is definitely no return() statement.

    I think I understand what you are suggesting, so what I did was change $SET['content'] to $body in both register.php and index.php where I echo the variable.

    Still, it does not show

  • #13
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,038
    Thanks
    2
    Thanked 316 Times in 308 Posts
    You would need to post all the code in register.php and your main file to get more specific help with why it is not setting or keeping the value in the variable.

    Since it is echoing your "hi" statement at the start of the include file, something is either happening with the code execution path or with the setting or unset()ing of the variable. If you assign a NULL or "" to the variable the variable will still exist and you would not be getting the "undefined" error message.

    It is also possible that if you are setting this inside of a function that it won't exist outside the function (which is what Fumigator posted.)

    Short answer - we only see what you post here. If you cannot find the cause, you will need to post your actual code.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #14
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    index.php

    PHP Code:
    <?
    session_start
    ();
    ini_set ("display_errors""1");
    error_reporting(E_ALL);
    require(
    'includes/config.php');
    require(
    'includes/menu.php');
    require(
    'includes/actions.php');


    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>GOTO-League.com</title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <style type="text/css">

    /* General layout */
    a:link {
        font-weight: normal;
        text-decoration: none;
        color: #005177;
    }
    a:visited {
        text-decoration: none;
        color: #005177;
        font-weight: normal;
    }
    a:hover {
        font-weight: normal;
        text-decoration: underline overline;
        color: #003300;
    }
    body {
        background: #ffffe1;
        color: #003300;
        scrollbar-face-color: #006752;
        scrollbar-arrow-color: #ffffe1;
        scrollbar-track-color: #ffffe1;
        scrollbar-shadow-color:#000033;
        scrollbar-highlight-color:#66cc99;
        scrollbar-3dlight-color:#ffffff;
        scrollbar-darkshadow-Color:#003300;
        font-family: Arial, sans-serif; font-size:12px;
        margin-top: 0; margin-left: 0; margin-right: 0;
        padding-top: 0; padding-left: 0; padding-right: 0;
    }
    text {
        font-family: Arial, sans-serif;
        font-size: 80%;
    }
    td {
        font-family: Arial, sans-serif;
        color: #003300;
        font-size: 80%;
    }
    input {
        background-color: #ffffe1;
        font-family: Arial, sans-serif;
        font-size: 9pt;
        color: #003300;
    }
    textarea {
        color: #003300;
        background-color: #ffffe1;
        font-family: Arial, sans-serif;
        font-size: 9pt;
    }
    select {
        background-color: #ffffe1;
        font-family: Arial, sans-serif;
        font-size: 7pt;
        color: #003300;
    }
    .copyright {
        font-family: Arial, sans-serif;
        font-size: 10px;
    }
    .bold {
        font-weight: bold;
    }
    hr {
        color: #006752;
    }

    /* YaBB navigation links */
    .nav {
        font-size: 90%;
        text-decoration: none;
        color: #003300;
    }
    .nav:link {
        font-size: 90%;
        text-decoration: none;
        color: #0000ff;
    }
    .nav:visited {
        font-size: 90%;
        text-decoration: none;
        color: #005177;
    }
    .nav:hover {
        font-size: 90%;
        color: #0000ff;
        text-decoration: underline overline;
    }

    /* YaBB alternating bgcolors */
    .windowbg {
        background-color: #cce6cc;
        font-size: 11px;
        font-family: Arial, sans-serif;
        color: #003300;
    }
    .windowbg2 {
        background-color: #ffffe1;
        font-size: 11px;
        font-family: Arial, sans-serif;
        color: #003300;
    }
    .windowbg3 {
        background-color: #cce6cc;
        font-size: 11px;
        font-family: Verdana;
        color: #003300;
    }
    /* Misc./title/category colors */
    .hr {
        color: #006752;
        background: #ffffe1;
    }
    /*table border style */
    .bord {
        border: solid 1 #006752;
        }

    /* cells top & bottom of news bar */
    .titlebg {
        background-color: #006752;
        color: #ffffe1;
    }
    /* headings in news bar & elsewhere */
    .text1 {
        font-style: normal;
        font-weight: bold;
        font-size: 12px;
        color: #ffffff;
    }
    .catbg {
        background-color: #cce6cc;
        color: #003300;
        font-weight: bold;
        font-size: 13px;
    }
    /* color of cell borders */
    .bordercolor {
        background-color: #006752;
        color: #ffffe1;
    }

    /* Image fonts */
    .imgbg {
        font-style: normal;
        font-size: 10px;
        color: #005177;
    }
    .imgcatbg {
        font-style: normal;
        font-size: 10px;
        color: #005177;
        font-weight: bold;
    }
    .imgtitlebg {
        font-style: normal;
        font-size: 10px;
        color: #ffffff;
        font-weight: bold;
    }
    .imgwindowbg {
        font-style: normal;
        font-size: 9px;
        color: #005177;
    }
    .imgmenu {
        color: #003300;
        font-style: normal;
        font-size: 11px;
        font-weight: bold;
        letter-spacing: 0.1em;
    }

    /* Post quote/code colors */
    .quote {
        font-size: 10px;
        font-family: Arial, sans-serif;
        color: #000000;
        background-color: #cce6cc;
    }
    .code {
        font-size: 12px;
        font-family: Courier New;
        color: #000000;
        background-color: #cccccc;
    }

    </style>
    <script language="JavaScript1.2" type="text/javascript">
    <!--
    if ((navigator.appVersion.substring(0,1) == "5" && navigator.userAgent.indexOf('Gecko') != -1) || navigator.userAgent.search(/Opera/) != -1) {
       document.write('<META HTTP-EQUIV="pragma" CONTENT="no-cache">');
    }
    // -->
    </script>
    </head>

    <body>
    <br>
    <table width="92%" cellspacing="1" cellpadding="0" border="0" align="center" class="bordercolor">
      <tr>
        <td class="bordercolor" width="100%">
          <table bgcolor="#ffffe1" width="100%" cellspacing="0" cellpadding="0" border="0">

            <tr>
              <td>
                <table border="0" width="100%" cellpadding="0" cellspacing="0" bgcolor="#ffffe1">
                  <tr>
                    <td bgcolor="#ffffe1" height="50"><img src="logo.jpg" alt="GOTO-League.com" title="GOTO-League.com"></td>
                    <td bgcolor="#ffffe1">
                    <p><font size="2"><span class="bold">
                    Hey, The Master, </span> you have <a href="http://goto-league.com/.//YaBB.pl?action=im">0 messages</a>.<br>

                    Jun 2<sup>nd</sup>, 2007, 11:07pm
                    </font><br></p>
                    </td>
                  </tr>
                </table>
              </td>
            </tr>
          </table>

        </td>
      </tr><tr>
        <td class="bordercolor" align="center">
          <table class="windowbg" width="100%" cellspacing="0" cellpadding="0" align="center" border="0">
            <tr>
              <td width="100%" align="center">
                <table border="0" width="100%" cellpadding="3" cellspacing="0" class="windowbg" align="center">
                  <tr>
                    <td valign="middle" class="windowbg" align="center"><font size="1">
                        <?=$SET['menu'];?>
                    </font></td>

                  </tr>
                </table>
              </td>
            </tr>
          </table>
        </td>
      </tr><tr>
        <td class="bordercolor" align="center">
          <table class="bordercolor" width="100%" cellspacing="0" cellpadding="0" align="center" border="0">
            <tr>
              <td width="100%" align="center">
                <table border="0" width="100%" cellpadding="5" cellspacing="0" class="bordercolor" align="center">

                  <tr>
                    <td valign="middle" class="bordercolor" align="center">
                    <font size="2" class="titlebg">« <?=$SET['title'];?> »</font></td>
                  </tr>
                </table>
              </td>
            </tr>
          </table>
    <?=$SET['conent'];?>
        </td>
      </tr>
    </table>
    includes/config.php

    PHP Code:
    <?php

    // includes/config.php

    $URL "http://www.goto-league.com";

    ?>
    includes/menu.php

    PHP Code:
    <?php
    // includes/menu.php

    $MENU['home'] = "<a href=\"".$URL."/index.php\">Home</a>";
    $MENU['register'] = "<a href=\"".$URL."/index.php?action=register\">Register</a>";
    $MENU['searchL'] = "<a href=\"".$URL."/index.php?action=searchL\">Search Leagues</a>";
    $MENU['searchT'] = "<a href=\"".$URL."/index.php?action=searchT\">Search Tourneys</a>";
    $MENU['login'] = "<a href=\"".$URL."/index.php?action=login\">Login</a>";
    $MENU['logout'] = "<a href=\"".$URL."/index.php?action=logout\">Logout</a>";
    $MENU['help'] = "<a href=\"".$URL."/index.php?action=help\">Help</a>";
    $MENU['contact'] = "<a href=\"".$URL."/index.php?action=contact\">Contact Us</a>";
    $MENU['reviews'] = "<a href=\"".$URL."/index.php?action=reviews\">GOTO Reviews</a>";
    $MENU['addL'] = "<a href=\"".$URL."/index.php?action=addL\">Add League</a>";
    $MENU['addT'] = "<a href=\"".$URL."/index.php?action=addT\">Add Tourney</a>";
    $MENU['space'] = "]&nbsp;&nbsp;&nbsp;[";

    // menu
    if (empty($_SESSION['id'])) {
        
    $SET['menu'] = "<DIV style=\"font-size:110%\">[".$MENU['home'].$MENU['space'].$MENU['register'].$MENU['space'].$MENU['searchL'].$MENU['space'].$MENU['searchT'].$MENU['space'].$MENU['login'].$MENU['space'].$MENU['help'].$MENU['space'].$MENU['contact'].$MENU['space'].$MENU['reviews']."]</DIV>";
    } else {
        
    $SET['menu'] = "<DIV style=\"font-size:110%\">[".$MENU['home'].$MENU['space'].$MENU['addL'].$MENU['space'].$MENU['addT'].$MENU['space'].$MENU['searchL'].$MENU['space'].$MENU['searchT'].$MENU['space'].$MENU['logout'].$MENU['space'].$MENU['help'].$MENU['space'].$MENU['contact'].$MENU['space'].$MENU['reviews']."]</DIV>";
    }
    ?>
    includes/actions.php

    PHP Code:
    <?php
    // includes/actions.php

    switch($_GET['action']){
        case 
    "register":
            
    // module
            
    $SET['module'] = "register.php";
            
    // title
            
    $SET['title'] = "Register New Account";
            break;
        default:
            
    // module
            
    $SET['module'] = "main.php";
            
    // title
            
    $SET['title'] = "Home";
            break;
    // switch

    require($URL.'/actions/'.$SET['module']);


    ?>
    actions/register.php
    PHP Code:
    <?php
    // register.php
    $SET['content'] = "hi";
    ?>

  • #15
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    Ummm you'll see in index.php I accidentally had it as "conent" instead of content, but this was after changing it back from body.. I've fixed it to say content but still getting error. Just thought I'd point that out before anyone said it was due to a typo hehe


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •