|
|
Send spam to: website@xeonlive.com nick@xeonlive.com georgiapeach1241@aol.com Taking web design to the next extreme By Red Squirrel
Here is how this script would look like when first opened:
And after you typed in the information and submit it…
Now, let's go through this script to see what it does and how it works. On line 1, the parser is told to start looking for php code and to parse it, so it does. On line 2, it checks if the variable $_GET[act] is empty, if it is, it executes what is in the { } brackets, if it is equal to something else, it keeps executing after the brackets. A $_GET variable is when you have something after the file name in the uri request (the address bar). Notice in the second picture how there's ?act=go This is saying that the GET variable called act is equal to "go". But if you don't add it, that variable is simply empty so it's equal to "". Now on line 3 we have the start bracket for the if statement. On line 4 we tell the parser to stop parsing php. So whatever it sees now, it will just send it away to the client as it is. So lines 5 to 9 are simple html code for a form with two text fields. One is called name and the other is called age. On line 10 we tell the parser to start parsing code again, the only thing to parse is a } which ends our if statement. Then, on line 13 we have another if statement, but because $_GET[act] is not equal to "go", the parser skips all what's inside, and that ends our script. But that's not all folks! We can make $_GET[act] equal to "go" so the second part is not just fancy coding that does nothing but sit on the server. All you have to do is type in script.php?act=go. But wait, that's not what we want, but it would work.. So don't put a link or anything since the form will be useless, we need to actually send the forum's entered data to the script. What we want to do is click the button. Notice on line 5 what we put for the action of the form? The form's action is simply the url it calls, but it's not like a normal link, because we are not using GET but POST. We set the method to POST for a reason. POST simply *posts* the data of the form to whatever url is put as the action. So we are posting "name" and "age" to script.php?act=go in this case. Now we know how to use $_GET variables, and now let's use $_POST. Post works the same way as GET, but instead, the variables are not set in the url, but are set "secretly" by the form. POST is good for passwords and other private info, as they do not appear in the address bar. When we push the button, the script skips the first if statement because $_GET[act] is equal to "go" and not "" (nothing). But it does not skip the second if statement because it complies to it, as $_GET[act] is equal to "go". So on line 16 we have a echo statement. Before you get scared of that one, let me explain quickly why it looks scary like that. In php, when you want to hook up strings together, you just plug it in with dots. So if you want to echo a variable and text at the same time, you put a dot between the text and the variable. Variables don't have quotes, but text has quotes. So you end up with "text".$variable. Also, all php variables start with $. In that particular echo, we are echoing the POST variables. Because our first field was called name, the variable is called $_POST[name], and the age one is $_POST[age]. The next page will further explain how variables work. Next Page
|
![]() |
This site best viewed in a W3C standard browser at 800*600 or higher Site design by Red Squirrel | Contact © Copyright 2010 Ryan Auclair/IceTeks, All rights reserved |