This is the start of a new series of articles on passing variables. A series about coding web pages with PHP. PHP is an interactive, interpretive, scripting language that works well with HTML to communicate with the database, and create dynamic applications for the Internet. As such this series will combine HTML and PHP to accomplish varies tasks.
The focus will be on passing variables. Why passing variables? Because the Internet is stateless. By stateless, I mean that every request going to the Internet server is independent of any other request. The Apache server delivers a web page from the server to the browser on your computer, and when you click on another link, probably a new server will deliver another page. The servers could be physically located half a world apart. How do we move data from one page to the other when each page stands on it own? The new page that loads, does not know anything about the preceding page, unless of course, you pass some informaton from the one page to the other.
And that's where the problems start. If I assign a variable on one page, that variable ceases to exist in the new page. It's gone. Variables only persist while in an individual page. If I type in my name on an Internet page, how does the new page repeat my name back, like Amazon does when you log in?
Well, that's a good question and the subject of this series. By passing variables, I mean passing data, whether its your name, or phone number, or the results you entered in a survey from one web page to another, or from the web page to the database and back to another web page. We'll focus on "Passing Variables," getting data moving around your system.
"Passing Variables" probably causes more problems in coding than any other issue. You pass the data a user fills out in a form, back to a "controller" file. This takes in the information, and assigns the indivual data to variables or an array. The information is validated and if there is an error, an error screen will be called, if the data is ok, We can pass these variables back to a "model" file for saving in a database, again passing variables between pages.
The next page comes up, calls a function to get the informaton out of the database, passes the data back to the new page, the new page shows the same form with the information you filled in the form populated in the form. The form page you filled in is a different page then the page that had the blank form you initially filled out, with perhaps an error message, saying a field you forgot is required.
We will cover some HTML and more PHP. Topics I hope to cover are: Forms, Get, Post, Cookies, Sessions, function variables, returns, arrays, and passing objects. As far as syntax, we will eliminate any extraneous html or php that is not necessary to make our point. You'll see no div's, or ul's. or li's. We assume you know what needs to go else where in the page to make it work, and are reading the post, because you just need that snippet of code to make it work. We definitely want to make the page an easy reference when your stuck to quickly look up the right code sequence and syntax, and you just want to know how to do that...
And with that...we're off...