I would like to address a problem that I have seen time and time again by newcomers that are posting for answers to why thier form does not post.

register_globals=on is your enemy. Starting with PHP version 4.2 the php.ini is set to off. What this means is that any book or tutorial that has been published before 4.2 was released is probably telling you a big lie on how to handle POST, GET, SYSTEM, SESSION, COOKIES. I know this is the case if you are using the book published by sams titles "PHP and MySQL Web Development" I know. I own the book. It does give you a good overview of the php/mysql language, but some of it is incorrect. There is a blurb in there stating that the way they are teaching you is wrong. They even reference to you that by turning register_globals=off in the php.ini is the correct way. Why they did that I don't know.

The point of my post is to be a possible reference to those wondering why they do not see thier variables after they hit the submit button. I will try and give some examples so that you will overcome your teachings of miss-information.

1. SessionsSessions are your friend. They allow you to preserve certain data across subsequent accesses. Which means you can transfer information from page to page. How this works is by using the session_start() function that is built into PHP. What this does is create a unique id that is sent to the clients computer in either the form of a cookie or through the URL. Please note that there has been talk of removing the method to set it from the URL.

If you are somewhat firmilar with sessions and are using session_register() this is not the best way to do it. Not only is there more code involved it also may confuse the living s@!$% out of you. There is a much easier way to do this.

Introduced into PHP 4.1 are Predefined Variables. These are a set of reserved variables that have made working with sessions and other functions as easy as simple arrays.

Using this method to set a session variable all you have to do is use the $_SESSION super global.

This will create a session variable that will remain untill you use session_destroy(), the user closes the browser, or the time you have specified times out. The information that is set within the $_SESSION[] can be accessed from page to page. This is good when using a shopping cart, restricting access to different pages, or even making sure that your webpage counter doesn't keep increasing when they hit the refresh button.

2. $_POST, $_GETOne of the most common problem that I see is people do not realize that they need to use these when posting a form. Just like $_SESSION this is a super global that is reserved in the PHP language. In a form tag it will have a method that you would like to use to post information if you use a post method your information will be contained in the $_POST variable as an array. If you use a GET method it will be in the $_GET variable once again as an array. Below is an example on how you would use this with a POST method form and a $_SESSION['error'].

That is a simple post form that when submitted it will check to see if there is actually information inputted into the text boxes and error out if any one of them is blank.

ConclusionI wanted this post to be a little longer. I did not cover $_SERVER, or $_ENV super global but you can follow some of the links I put in there and find some good information. I hope this has helped to shed some light a little. If there are errors in my code please let me know. This post was kinda on the fly so I have not actually tested the code. I may have missed a ; here or there so if the code don't work right out the box look for that. Peace out.

NOTE: if you want to put this as a sticky post please do so more people will see it and might save some repeat posts.

Last edited by Redcircle on Sun Jun 13, 2004 12:12 am, edited 1 time in total.

that is a very good example.
But can you give me a example how to create a login.wml
and validate the login with php and postgresql.
I have tried and searched a lot but i do not know how to send two variables that i get from my login.wml to the php file.
you can have a look at the topic:
PHP WML POSTGRESQL.

let me beter ask my question. this is my code, it works fine just am wondering what errors may occur if any in the future. I learned how to code like this in school, but i see that others do it defferently.

In the if stament im using quotes when calling the array. In the functin and when calling the arrays other places i usually donot use quotes similiar to $_vars[ProductID]. Like i said everything works fine, but as the last reply it is incorrect. WHY

You should always use quotes when referring to items in an associative array. If you set error_reporting to E_ALL, you'll see that you are causing errors (notices, actually), you're just not seeing them.

i do this for ease of coding for myself. by calling that if() stament on my pages i can easily use the same array name $_vars throught my site. yes i know that i can use POST an GET superglobals, but what i use seems to works just the same.

U are a super PHP guru, I am just a newbie. Am i doing something super wrong by calling my POST or GET vars that way?

You're not doing something "super wrong", but it could be done better.

The reason I advocate using $_POST and $_GET is so that you always know where your variables are coming from. It's just a good habit and gives you a little peace of mind. Another thing to consider is that with your code, if both POST and GET data are submitted in the same request (e.g. if your form has a POST method and and your action looks like "script.php?a=1&b=2"), only the GET data will wind up in your $_vars array.

i see, and will remember your wisdom. currently i have bno get variable in the action of a from. i use hidden input tags within the form to pass my vars. but i will keep in mind. thank you soo much for the wisdom