[thelist] help me understand global variable in PHP

Tom Dell'Aringa pixelmech at yahoo.com
Thu Jan 2 12:10:00 CST 2003


I'm having some trouble getting a variable value in my page. My code
uses some global variables which I don't really understand. Here is
what happens:
---------------------------------------
First, the script declares the variable:
$prodname = "";
---------------------------------------

Then, I am parsing XML, which uses 3 user defined functions called
by:
---------------------------------------
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
---------------------------------------
(its event driven, every time the parser hits a handler, it runs the
appropriate function, same for character data)

Within the three functions I have the following line:
---------------------------------------
global $prodname (with some other vars)
---------------------------------------

Then, at the end of the endElement() function (the last one to deal
with the data) the variable is again set to blank
---------------------------------------
$prodname = "";
} (end function)
---------------------------------------

Now, my problem is - I want to pass along $prodname to the next page
I am going to via the query string. So I have something like
/path.php?p=$prodname. This variable however is always empty. This
line of code is OUTSIDE the functions of course.

Now, I assume this is part of the problem, $prodname gets set to
blank so there is no value. So I tried, inside the function doing

$prod = $prodname;

so it wouldn't get reset..this still doesn't work.

You can see the full page code at:
www.silverheaven.com/reg/code.html.

If you look at the code, I am having a similar problem with
$message..

Tom



=====
var me = tom.pixelmech.webDeveloper();

http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com



More information about the thelist mailing list