Announcement

Collapse
No announcement yet.

Custom Global Variable Problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom Global Variable Problem

    Hi, iam having a hard time getting my variables that I set in the phpinclude template to be useable. Iam accessing my database and returning 2 values , which is working fine ... I can see the variables when I echo them on the spot and exit. However if I try and use those variables in a template , the values are NULL. Iam assuming Iam having a variable scope issue, any suggestions would be greatly appreciated. Thanks

    Rory

    register_globals is off btw
    Last edited by Rory; Mon 14th Oct '02, 2:35pm.

  • #2
    This should work perfectly fine:

    in phpinclude:
    PHP Code:
    $stuff 'w00t!'
    in any other template:
    Code:
    $stuff
    ...should show "w00t!".
    --filburt1, vBulletin.org/vBulletinTemplates.com moderator
    Web Design Forums.net: vB Board of the Month
    vBulletin Mail System (vBMS): webmail for your forum users

    Comment


    • #3
      Here is my phpinclude file :

      // This code is PHP4 only:
      // ob_start();
      // require("yourheader.html");
      // $header = ob_get_contents();
      // ob_end_clean();

      $authed_user = $_SERVER['PHP_AUTH_USER'];

      mysql_connect("localhost", "####", "#######");
      mysql_select_db("######");

      if (!$authed_user) {
      exit;
      }

      $query = "SELECT board_username,board_password from subs where u_name = '$authed_user'";
      $result = mysql_query($query);
      $make = mysql_fetch_row($result);
      $b_username = $make[0];
      $b_password = $make[1];


      if (!$b_password || !$b_username) {
      $b_username = "NoUser";
      $b_password = "password";
      }

      #echo "u:$b_username p:$b_password";
      #exit;

      When I uncomment the last 2 lines it echos the correct username and password and exits. When I comment the ehco comman and exit out (so it runs through the entire page), the variables arent being replaced on my template. Here is a copy of my username_loggedout template :

      <tr valign="top">
      <td><input type="hidden" name="username" value="$b_username" size="25">
      <input type="hidden" name="password" value="$b_password" size="25"></td>
      </tr>

      When I view the source of the page the values are showing as "". It seems like it would work but iam obviously doing something wrong. Thansk for the help.

      Rory

      Comment


      • #4
        Maybe the condition is simply never met and the $make array is empty?

        Try putting a dummy variable in that relies on no conditions and see what happens. It seems like you're doing the right thing, except for echoing which tends to confuse vB and give eval'd code errors on some pages.
        --filburt1, vBulletin.org/vBulletinTemplates.com moderator
        Web Design Forums.net: vB Board of the Month
        vBulletin Mail System (vBMS): webmail for your forum users

        Comment


        • #5
          Here is modified code :

          // This code is PHP4 only:
          // ob_start();
          // require("yourheader.html");
          // $header = ob_get_contents();
          // ob_end_clean();

          $beer = "Hot Sauce";

          and my username_loggedout template

          <tr valign="top">
          <td>beer=$beer</td>
          </tr>

          When run outputs beer=

          Comment


          • #6
            OK, still banging my head against thge monitor but that doesnt seem to be helping. Any other ideas anyone? Thanks.

            Rory

            Comment

            widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
            Working...
            X