Jump to content

Archived

This topic is now archived and is closed to further replies.

RyanEricW

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

Recommended Posts

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 [i]FOUR KING[/i] SENSE. I'm so mad right now because I don't understand WHY?!

Here's my index.php

[code]
<?
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]);
}
?>
[/code]

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

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

[b]SA: Edited unnecessary swearing from post[/b]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
require_once('src/src_skin_macros.src');

contains the array.

[code]
<?

$skin = array();

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

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

?>
[/code]

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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
[code]function sql_connect_real($database)
{
    global $skin;[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=384244:date=Jun 15 2006, 11:04 AM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 15 2006, 11:04 AM) [snapback]384244[/snapback][/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.

Share this post


Link to post
Share on other sites
How do you define these [i]global[/i] arrays then? Its quite simple really.

This will NOT work.
[code]
<?php

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

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

  bar();

?>
[/code]
This WILL.
[code]
<?php

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

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

  bar();

?>
[/code]
And an even better way avoiding globals.
[code]
<?php

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

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

  bar($foo);

?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.