new to PHP .....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mzfp
Forum Newbie
Posts: 3
Joined: Sun Apr 28, 2002 7:31 am
Contact:

new to PHP .....

Post by mzfp »

im absolitely new to PHP, and have set it up on my local computer to run with Apache as an SAPI module. Everything works fine, except when processing a form, the page that is loaded to deal with the form data, doesnt seem to be aware of the form values

eg a input names name in my form, should be accessed on my php page as $name, but this doesnt print out any value.

This is only the case on my computer, when i upload it to my server, which allows PHP scrpting, it works fine.

Any suggestions, maybe i havnt installed some modules? if so how do i install them, and which ones?

thanks
M[/b]
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Instead of $name, use $_GET['name'] or $_POST['name'].

$_GET if you are passing the values by the get method, or $_POST if you are passing by the post method.

Let me know if it works, and I will tell you why. =)
mzfp
Forum Newbie
Posts: 3
Joined: Sun Apr 28, 2002 7:31 am
Contact:

it wrked ! :-D

Post by mzfp »

thanks mate, it worked, and u saved me alot of time crawling round the web looking for a solution! .. so why does it work is the nex natural question!
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Because, as you mentioned, you are new, and that would mean you just installed PHP 4.2.

If you read on this page: http://www.php.net/release_4_2_0.php

This part:
External variables (from the environment, the HTTP request, cookies or the web server) are no longer registered as global variables
This is where your problem occured.

You were attempting to access a variable from a Get or Post method, or an external variable (Sessions, Cookies, and such also fall into this category) directly, as a global.

For security purposes, these are disabled. However, you can change that.

All you have to do is edit the php.ini file.

Look for this line:

Code: Select all

register_globals = off
And switch it with this:

Code: Select all

register_globals = on
Now, I would recommend doing that, however, I also urge you to use $_GET and $_POST over directly accessing the variable like you were. This is for security reasons and what not.

You can read more about that and the reasons here: http://www.phpadvisory.com/articles/view.phtml?ID=1

Good luck :D
Post Reply