Forum Moderators: coopster

Message Too Old, No Replies

Why $_POST[$variable] and other times just $variable

I try using $variable_name and doen't work

         

digi_mind

7:49 am on Apr 7, 2003 (gmt 0)

10+ Year Member



I made a simple, very simple script to allow a user to enter his / her name and when I try to see the information after clicking on submit it didn't work:

if($submit)

that is what doen't work, the submit button seems to not be active or something like that.

If I try:

if($_POST[$submit]) // it does work.

The question is simple, why in some computers the first statement works in other ones it doesn't?

mavherick

7:55 am on Apr 7, 2003 (gmt 0)

10+ Year Member



It depends on how php is configured. With register global [php.net] turned on, using $submit will work cause php will automatically create the var for you. But if it's turned off, you have to retrieve it in the $_POST[] array.

mavherick

digi_mind

7:59 am on Apr 7, 2003 (gmt 0)

10+ Year Member



I guess register global off is much better for security reasons. Am I right?

mavherick

8:09 am on Apr 7, 2003 (gmt 0)

10+ Year Member



You're right, even if it's turned on, I prefer to use $_ arrays as I'm forcing myself to make sure I know with which var I'm playing around. And it's also handy when you have for example identical named var in a query string and a form. Using $_POST['myvar'] and $_GET['myvar'], you're sure you're getting what you were looking for, although it's not a good idea to end up with identical var name like that in the first place.

mavherick

Xuefer

9:44 am on Apr 7, 2003 (gmt 0)

10+ Year Member



> if($_POST[$submit]) // it does work.
but no, it's not real "work"

for: <input name="submit" value="submit" />
$submit = "submit"
so $_POST[$submit] seems to work
it's just actually $_POST["submit"]

if u do: $submit = 123;

if($_POST[$submit]) // it doesn't work!

so use $_POST["submit"]