Computing.Net > Forums > Programming > PHP5 and global variables

PHP5 and global variables

Reply to Message Icon

Original Message
Name: Patchy
Date: September 13, 2004 at 13:01:00 Pacific
Subject: PHP5 and global variables
OS: Windows XP Proffessional
CPU/Ram: AMD Athlon XP 1.6Ghz, 256
Comment:

Im having great difficulty with PHP5 and my current project.

The environment is:
PHP5 and MySQL4.0.20a-nt running on IIS V5.1 on Windows XP Professional. Im accessing the website through localhost.

Now, I have a website in development. The user will only see index.php, as it loads individual 'modules' from another directory. A file, core.php, (containing functions required for every module) is "include" along with config.php which is "require_once".

Now the first problem I had is one module could use the CMySQLOpen function (in core.php) with no problems, but another module couldnt. The first line of the function is:

global $sqldbhost, $sqlusername, $sqlpassword, $sqldbname;

These vars are declared in config.php, which is required on the second line of core.php.

I stepped through it right up until the function is called, yet it is not declaring the said variables as global once in the function.

This was solved by putting the line

global $sqldbhost, $sqlusername, $sqlpassword, $sqldbname;

in the function which calls CMySQLOpen.

Now I have a new problem. A cut down version of the module follows:

<?php
$img = @$HTTP_GET_VARS["img"];
$cat = @$HTTP_GET_VARS["cat"];
$subc = @$HTTP_GET_VARS["subc"];
/* I have to declare variables like this as it gives me an error telling me that $img or $HTTP_GET_VARS["img"] is not defined */

$artworkimages = "artworkimages";
$gallerycategory1 = "gallerycategory";

function catmenu() {
global $gallerycategory1;

/* Call from core.php, this works fine in this module, as it has been called from index.php */
$linkid = CMySQLOpen(null);
$result = mysql_query("SELECT id, title, active, menuorder FROM $gallerycategory1 WHERE active='y' ORDER BY menuorder ASC ") or die(Csql_error("module_gallery","imgpopup"));

while($query_data = mysql_fetch_row($result)) {
$catid = $query_data[0];
$cattitle = $query_data[1];
$catactive = $query_data[2];

echo $cattitle . " will be hyperlinked with ID as an Arg.
\n";
}

}
?>


This gives me a MySQL error telling me $gallerycategory1 is of null value.

I cant think whats up here... is there a PHP variable buffer i need to set in php.ini?! Is this a bug issue with PHP5?!

If you read all through this, thanks!


Report Offensive Message For Removal

Response Number 1
Name: Patchy
Date: September 14, 2004 at 10:39:08 Pacific
Subject: PHP5 and global variables
Reply: (edit)

Nevermind, Solved.

php.ini wasn't set up correctly.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: PHP5 and global variables

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software