[thelist] php: problem with variable

Michael Galvin mpgalvin at eircom.net
Wed Jan 23 08:40:55 CST 2002


I'm a complete nimrod when it comes to php, but in an attempt to learn it, I
downloaded a project from melonfire.com ("The Vault"), so that I could
examine it, see how it works, etc.

Well, it would appear that it was written in an older version of php than I
have (4.1.1 win) and I'm getting some problems.  The major one was that
mysql_db_query() has been deprecated and replaced with mysql_select_db() and
mysql_query(), but I managed to sort that out.

Now I'm having some trouble with what appears to be undefined variables,
which I assume didn't cause much of a problem in whichever version of php
this was originally written.

I have an add.php which submits a form to itself.  So the first thing it
does is check for a variable called '$submit' which is the value of the
submit button.  If this is empty, it creates the form.  If not, it does some
other stuff (not important).

Originally, the module had:

If (!$submit)
{...print form

but I was getting undefined variable errors.  So I changed it to:

If (!defined('$submit'))
{...print form

(and you wouldn't believe how long it took me to figure even that out!).
Now it just seems to ignore the fact that I've pressed the button, ie., the
result of "!defined('$submit'))" is 1 (true), even though "print $submit;"
returns the correct answer.  Going back to RTFM I noticed that "defined()"
works for constants, implying it wouldn't work in this case, right?  So how
would I go about doing this?





More information about the thelist mailing list