View Single Post
  #22   Spotlight this post!  
Unread 23-02-2005, 17:43
Mike's Avatar
Mike Mike is offline
has common ground with Matt Krass
AKA: Mike Sorrenti
FRC #0237 (Sie-H2O-Bots (See-Hoe-Bots) [T.R.I.B.E.])
Team Role: Programmer
 
Join Date: Dec 2004
Rookie Year: 2004
Location: Watertown, CT
Posts: 1,003
Mike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond repute
Re: Teach Genia How to Program and Win a Prize

Here's some old PHP tutorials I wrote a while back, finally found them.

PHP Tutorials

PHP Tutorial Lesson 1

Introduction:
Hopefully by the end of these tutorials you will have enough knowledge to make your own web-based games. However there are alot of things you'll need to cover by yourself. I have also made this tutorial so that you won't need any fancy "Make a website in 24 hour" software. Dreamweaver is not needed. I recommend Crimson Editor. I will be making reference to it throughout the tutorials. Lesson 1 will be about Proper Coding.

Proper Coding
Of all the most annoying things I could single out easily one MAJOR problem among beginning and expert coders alike. The code layout, the code may work fine but it is hell on the eyes and if/when you come back to it in a while it will be very hard to understand. You should always write your code so that it is easily readable in case you get it wrong the first try, also if you were ever to hire a new coder this will make their job ALOT easier. Here are the basic principle elements

* User Friendlyness
* Legibility
* Finding Errors



User Friendlyness:
The way your scripts operate should be easy to understand without any confusing functions. A user may try to make a username such as Mike's Account, your program should be able to catch the ' and tell the user that it is an illegal character (because of the security risk it poses, you will learn about this later on). Now instead of automatically replacing the ' with say, a space, your script should notify the user that a ' is an illegal character. Following these guidlines will also help you keep down the need for support. Error messages should also be user friendly, you can get some pretty gruesome error messages that will confuse your users, with some simple error handling you can display a user friendly error and possibly give some links to notify your technical staff.

Legibility:
Your code should be readable, heres an example of some bad code
Code:
<?php
$the_password_that_the_guy_used = $_POST['password'];
if($the_password_that_the_guy_used == "password"){
$afdafdsaf = "welcome";
}else{
$afdafdsaf = "your not him!";
}
echo $afdafdsaf;
?>
Now there are a few things wrong with this code, first off there is no indentation. By indenting your code you are making it much easier to match up your brackets, your if/thens, and saving yourself alot of time! Yet another problem our Joe Newbie has is his looooooong variable names. Variables should get down to the point, using prefixes or whatever you need to use. Instead of $the_password_that_the_guy_used you could just use $password, this saves more time without having to type all that unneeded junk. His final problem is his odd choice for variable names. He is just asking for errors, this name is very easy to mistype, which would lead to an error, or displaying nothing at all (depending how your server is set up). After much review here is his new code
Code:
<?php
     $password = $_POST['password'];
     if($password == "password"){
          $message = "welcome";
     }else{
          $message = "your not him!";
     }
     echo $message;
?>
Finding Errors:
99.9% of your errors will come in this form


What I usually do in this situation is copy the problem part, google it, and read some answers to other peoples problems. If it is relevant to my problem then usually it fixes it, however if that doesn't work then I will open up my code in Crimson Editor and find the error line. One thing to remember about PHP is that it doesn't say what line the error is on but what line the page crashed on. For example if my bike got a flat tire at yard 10 and I hit a tree at yard 30 PHP would say that the error was on yard 30. Get it? Good.

Conclusion:
To wrap up the first part of my tutorial, i'd like to give some good php sites.
Help Sites
PHPFreaks Site
PHPFreaks Forums
PHP Enabled Free Hosting
Hostultra
Spunge *Recommended!*

Next Tutorial:
My next tutorial will cover variables and if/then statements. We will write some basic code to allow very simple user login.

Note:
If you have anything to contribute feel free to PM or email me
__________________
http://www.mikesorrenti.com/
Reply With Quote