Jump to content


Photo

Variables....Frustrated....Angered.....


  • Please log in to reply
7 replies to this topic

#1 RyanEricW

RyanEricW
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 15 June 2006 - 02:10 PM

I've spent hours trying to debug this situation which I put my-self into.
The problem is, for some ODD reason, this stupid function does not want to add the error string to it.
MAKES NO FOUR KING SENSE. I'm so mad right now because I don't understand WHY?!

Here's my index.php

<?
session_start();

//------------------------------------------------------>
//--------------------> Initialization
//>
//Initialize the data for the layout
require_once('src/src_skin_macros.src');

//Include Custom Error Handlers
require_once('src/src_messeges.src');

//Loading configuration
require_once('src/src_config.php');

//Including Global Functions
require_once('src/src_globals.src');

//------------------------------------------------------>

function sql_connect_real($database)
{
    $connect = sql_connect($database);

    if($connect == -1)
    {
        $skin['content'] = $skin['content'].$error['mysql_generic'];
    }

    if($connect == 0)
    {
        $skin['content'] = $skin['content'].$error['mysql_db'];
    }
}

// Load Page Data
if(isset($_GET['idx']) == 1)
{
    $pagename = $_GET['idx'];

    if(file_exists("pages/page_$pagename.src") == 1)
    {
        include("pages/page_$pagename.src");
    }
    else
    {
        $skin['content'] = $skin['content'].$error['file_inexistant'];
        sql_connect_real("FORKYOU");
    }
}

if(isset($_GET['src']) == 1)
{
    $srcfile = $_GET['src'];

    if(file_exists("src/src_$srcfile.src") == 1)
    {
        include("src/src_$srcfile.src");
    }
    else
    {
        trigger_error($error[file_inexistant],E_USER_ERROR);
    }
}

//Load the layout
if(!file_exists($config[skin_layout]))
{
    trigger_error($error[skin_notfound].$config[skin_name],E_USER_ERROR);
}
else
{
    require_once($config[skin_layout]);
}
?>

Now what I'm doing is triggering a not found page, which leads me to
        $skin['content'] = $skin['content'].$error['file_inexistant'];
        sql_connect_real("FORKYOU");

Now I put that name for the DB to make sure it does not connect to the DB to test it.
It returns the correct number "0" for not connecting to the DB, but it does NOT format the $skin[content]!!!!!!
WTF?!
But yet below that, it'll add things to the skin content.

IF anyone is serious about helping me, I can send you the files over aim and describe it a bit better.
Thanks.

AIM: ryanericw

SA: Edited unnecessary swearing from post

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 15 June 2006 - 02:28 PM

The $skin array does not exist within the sql_connect_real() function. Go back to the manual, read up on functions and variable scope, calm yourself down and get on with it.

#3 RyanEricW

RyanEricW
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 15 June 2006 - 03:03 PM

require_once('src/src_skin_macros.src');

contains the array.

<?

$skin = array();

//Administration
$skin['loginbox']        = "login();";

//Layout - Center
$skin['title']            = "";
$skin['content']        = "";

?>

On a side note, I've noticed many scripters use
$this->
before something.
I wanted to know exactly that does, because whenever I try looking for it through a search engine, nothing shows up.

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 15 June 2006 - 04:01 PM

Go back to the manual (look... Ive even gone and got you a [a href=\"http://au.php.net/manual/en/language.variables.scope.php\" target=\"_blank\"]link[/a]), read up on functions and variable scope.

As for your other question, there is a thread posted in the [a href=\"http://www.phpfreaks.com/forums/index.php?showforum=41\" target=\"_blank\"]FAQ/Repository[/a] that answers your question.

#5 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 15 June 2006 - 04:04 PM

As thorpe said, RTFM.

I'd be a little more polite when asking questions because most of the people would just ignore you for less than that.
~ D Kuang

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 15 June 2006 - 04:25 PM

If you are using variables that are outside of a function you will need to make them global in order for the function to use those variables. Like so
function sql_connect_real($database)
{
    global $skin;


#7 RyanEricW

RyanEricW
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 16 June 2006 - 01:56 AM

[!--quoteo(post=384244:date=Jun 15 2006, 11:04 AM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 15 2006, 11:04 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
As thorpe said, RTFM.

I'd be a little more polite when asking questions because most of the people would just ignore you for less than that.
[/quote]

RTFM is an acronym that includes foul language. I'm suprised the mod/admins haven't done anything about that*.

You guys just don't understand though, I'm using global arrays, and I'm trying to edit it's content and distribute it through to index.php as the final product, but that doesn't happen because of the way my files are included.
I do admire you guys for trying, but not a one of you helped, and it may have been possibly due to me not explaining it well enough, but answers such as RTFM don't help me much. Not only is this agrivating, but when I go someone to ask for help I get even more argrivated due to lack of maturity amongst some. A simple "Try taking a look at the manual" or "I believe it's included in the manual, try there" would have been just fine.
For those who tried to help me without being ignorant. Thank you, it is greatly appreciated. [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
As for you others, I hope you one day mature a bit better.

#8 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 16 June 2006 - 02:45 AM

How do you define these global arrays then? Its quite simple really.

This will NOT work.
<?php

  $foo = array(1,2,3,4,5);

  function bar() {
    print_r($foo);
  }

  bar();

?>
This WILL.
<?php

  $foo = array(1,2,3,4,5);

  function bar() {
    global $foo;
    print_r($foo);
  }

  bar();

?>
And an even better way avoiding globals.
<?php

  $foo = array(1,2,3,4,5);

  function bar($arr) {
    print_r($arr);
  }

  bar($foo);

?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users