Misc Links
Forum Archive
News Archive
File DB



Latest Forum Topics
wow 56 k modems are
Posted by Red Squirrel
on Oct 14 2013, 11:52:23 pm

I Need A Program
Posted by rovingcowboy
on Sep 23 2013, 5:37:59 pm

having trouble witn lan
Posted by rovingcowboy
on Sep 23 2013, 5:40:56 pm

new problem for me
Posted by rovingcowboy
on Sep 23 2013, 5:54:09 pm

RBC Royal Bank
Posted by Red Squirrel
on Aug 13 2013, 6:48:08 pm


Php how-to for starters
Taking web design to the next extreme
By Red Squirrel

       What makes php a must in certain situations is when you need to use variables. They can either ask for user input, or produce their own input (ex: current date and time). But the thing is, it's dynamic, so without variables there would not really be a point to php. There is somewhat possibility of displaying dynamic stuff with html with javascript, but it is quite limited. In php you can do more. Here is a simple script that incorporates the GET and POST variables and also shows you more on the echo function and as well as the if statement.

1. <?php
2. If($_GET[act]=="")
3. {
4. ?>
5. <form method="post" action="script.php?act=go">
6. Enter your name: <input type="text" name="name"><br>
7. Enter your age: <input type="text" name="age"><br>
8. <input type="submit" value="done!">
9. </form>
10. <?php
11. Return;
12. }

13. if($_GET[act]=="go")
14. {
16. echo("Your name is ".$_POST[name]." And your age is .$_POST[age]."<br>Goodbye");
17. }
18. ?>

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
395481 Hits Pages: [1] [2] [3] [4] [5] 28 Comments

Latest comments (newest first)
Posted by halojoy on June 06th 2005 (22:36)
Yes, it is nice with scripts that does note produce notices.
isset is a good way to avoid this,
if you do not want to add a lot of code that sets 'empty' values for variables

Another way is to TURN OFF reporting of NOTICE
you add this, at top (beginning) of your php pages:

// Report ALL, but not NOTICE
error_reporting ( E_ALL & ~E_NOTICE );

// You will still get WARNINGS and other real ERRORS
// Notice is not an error, just a note
// To not have to add it in all your pages you can make it a line in 'config.php' ,
//  if you have such a file, that is included by php pages
I use E_ALL = reporting with notices only when working with my code
When I am finished and put my code on website, I Turn Notice OFF, using that line.
I do not want to scare my visitors laugh.gif

Posted by Red Squirrel on November 11th 2004 (14:13)
You need to run it off a webserver that has php installed.

So you would type http://serverhost/script.php

Posted by Red Squirrel on October 10th 2004 (16:32)
It means you have a syntax error in your mysql query, unfortunatly mysql is not very helpful at telling WHAT the error is, so you'll have to figure that part out. Post the query and maybe I can look at it and find the problem.
Posted by jewboy419 on October 10th 2004 (15:34)
pressanykey.gif i am doing a php on euoropean lycos and i get an error when using this code: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near" the first line of the code... can' anyone help!!!
Posted by sintekk on October 10th 2004 (11:18)
QUOTE (Red Squirrel @ Jul 6 2004, 08:41 PM)
Tripod actually has php amd mysql? That's cool, I did not know that.

Only the European lycos, the US one still believes that everybody that wants a website with them just wants to make a Hillary Duff fan page laugh.gif

...now only if there was a free ColdFusion host out there sad.gif...

View all comments
Post comment

Top Articles Latest Articles
- What are .bin files for? (669062 reads)
- Text searching in linux with grep (161180 reads)
- Big Brother and Ndisuio.sys (150471 reads)
- PSP User's Guide (139547 reads)
- SPFDisk (Special Fdisk) Partition Manager (117240 reads)
- How to Use MDADM Linux Raid (188 reads)
- What is Cloud Computing? (1225 reads)
- Dynamic Forum Signatures (version 2) (8769 reads)
- Successfully Hacking your iPhone or iTouch (18714 reads)
- Ultima Online Newbie Guide (35906 reads)
corner image

This site best viewed in a W3C standard browser at 800*600 or higher
Site design by Red Squirrel | Contact
© Copyright 2020 Ryan Auclair/IceTeks, All rights reserved