Prerequisites:
- None
What tools you will need:
- Computer
- Web browser
- Text editor
What you'll be learning:
- What's PHP and why you want to learn it
- What's a server
- What's database server and how it works with PHP
- Why's HTML necessary for PHP programmers
1. What's PHP?
- PHP's a interpreted(means it's run without the need to compile) high-level(basically high mean easy, low mean hard. psst! gurus don't bother arguing!).
Here's a little a little pyramid from webomedia on high/low level languages
Basically a low level language is something very close to what your machine understands, and high level is where most of the work's already done, you don't really need to understand what's going on and is very different than what machine understand. Another good example of high level is python.
Why do I learn PHP?
PHP is one of the languages you can use to interact with server. You can build application that work on the backend processing information that came from client(you). Don't forget PHP still is used in millions of servers! don't let people tell you PHP's getting old.
What's a server?
Server's a computer with some software installed that can interact with client when requests are made. When you write a website name is address box and press enter, a request to server is sent, server then decides what to do with that requests. Should it be denied? should user location be redirected, should it pass info to PHP module? A commonly used server is Apache!
What's a database server?
Database server is just another server installed on a computer, which interects with apache. For example, if you open google.com apache will run index.php file, from there index.php file will take over. It can either process whatever it needes itself or it can use SQL extention to interect with database, fetch info off there and return it to client or do whatever it needs to. Here's a little screenshot form daniweb.
What does PHP programmer need to know HTML?
HTML is a markup language which helps end user transmit data to server. A good example is forms. Whenever you press login button, your data is sent to PHP server through POST(it's just type of request, another basic request is GET, when you type www.google.com in addrss bad, get request is made). Though you don't need to be wizard basic HMTL is really needed.
Tricky part for beginners!
Your computer is also called client, it's in front of you. But the server you're making requests to is not, it's on cloud. Cloud basically means it's located somewhere. But it's still a computer. No magic here. Now thing about PHP is as I said it's a backend language, it runs in the server. NOT ON YOUR COMPUTER! PHP processes everything on the server.
I don't have server, how do I run PHP do I need to invest money?
No you do not, you can use local server, means you turn your computer into a server and run PHP! WAMP is a server you can use for windows. You basically installed it and open localhost to run whatever PHP you have.
Okay now go to C drive(could be different) > Wamp > www and create a file named index.php. Remember whenever you load the page index.php will automatically load. It's just default server(apache) setting. Alright with index.php created open your browser(localhost), type hello world in index file and save it. Reload you browser and you should see hello world message?
Guess what's happening right now? Basically for server to know you're running PHP you're required to have PHP code inside <?PHP ?> tags, whatever you do not type inside <?PHP ?> tags will run by your browser not server! lets try again <?PHP echo 'Hello world' ?>. Here's another tricky part. Whatever's inside PHP tag runs on server, by the way whenenver you are writing piece of text, it has to be inside quotation, 'text', it's also called string and echo means you want to print it to screen. So we run PHP code, now when it comes to echo, it will return that hello world piece of string to browser and browser it show it.
Alright now understand PHP were can I learn more about it?
PHP.net
If you're still reading, let get down some basic programming stuff.
What's a variables?
Variable's a an empty box, where you store stuff. For example, $x = 10; means you're storing 10 inside x, so if you go ahead and type echo $x; you'll see 10. What about echo $x + $x; ?? you'll see 20!
What's a string?
String's a piece of text and has to be inside quotation marks or you'll see error. What if you wanna store someone's name inside variables? $name = 'jon'. That's about you do.
What's an array?
An array is just like a variables but you an store multiple values inside it. For example, $x = []; Remember that braces, put multiple values inside it. $x = [10, 20, 'jon'], see you can put number aswell as string? you can also put in different data type, like boolean, object. Boolean's just true of false by the way. Also so what if we wanna show that array data on screen? Well lemme tell you this, each value in the array is represented by a number 0 , 1, 3, 4 etc.. so 1'st value is represented by 0, send, 2nd by 1 and so on.. so to show 1st value we do echo $[0];
Whats loop?
Wanna write something 1000 times on screen? well you could very well do echo 'someting', echo 'something' 1000 times... but if you use loop you could make it repeat 1000 times. Here's syntax for basic loop.
What's if confition?
If conditions are used to check if something is equal to something or if something's smaller than something or if something has a value and whatnot.
What're functions?
Suppose you wanna create a machine and whenenver you put water in it boils it! function's pretty much something that does same task over and over agan whenever you run it. We could have a function that when given 10, print 10 times table. It's used to organize code. One commonly used function is PHP is empty(); it checks if variables you're providing in is empty or not. Basic syntax or function is funcName(paramater).
Basic loop in PHP
Basic funciton is PHP
function hi(){
echo "hi";
}
continued..




![[IMG]](https://dl.dropboxusercontent.com/u/28490184/collect_email/persuade.png)
![[IMG]](https://dl.dropboxusercontent.com/u/28490184/collect_email/collect_mail.png)
![[IMG]](https://dl.dropboxusercontent.com/u/28490184/collect_email/valid_email.png)
![[IMG]](https://dl.dropboxusercontent.com/u/28490184/collect_email/final.png)
![[IMG]](https://dl.dropboxusercontent.com/u/28490184/collect_email/set_email.png)
![[IMG]](https://dl.dropboxusercontent.com/u/28490184/collect_email/site_info.png)
![[IMG]](https://dl.dropboxusercontent.com/u/28490184/collect_email/show_download.png)

