• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

PHP Paxton's Web Development School Part: 1

Paxton

Banned User
Joined
Feb 23, 2008
Messages
4,110
Reaction score
48
Location
London, UK
Hello, this is my first tutorials named Paxton Web Development School, this is part 1.

It's my first tutorial so I will introduce to people that do not know me :)

My name is Michal im from Poland but curently living in London, and I'm 16 years old.
I started all this when I was 10, I learned HTML, and I was learning everything randomly, I mean i was trying to learn everything, starting from HTML going through C++ finishing at video designing, now I'm doing it sixth year, but from about 1,5 year I'm sure what I will do in future, this is website Developing. I'm working now in IT company in Website Developing office also I have some friendship with other companies, so if they have something then they write to me.

If you are still not sure what you wish to do, but you are sure something with ICT, I will point for you few adventages and few disadventages of website developing.


Adventages:

- A lot of ICT work is for Website developers, actually it is the one of the most wanted job in IT now.
- You don't have to spend hours for rendering.
- It's not so hard, and it gives a lot of pleasure after finishing task.
- You don't need super PC to be a Website Developer, and programs needed are only few MB.

Disadventages

- You need to know much more languages than in 'making programs'
- You need to be very good to get a good paid job for it, and have year or more of clear experience.


So even if you don't want to become a Website Developer, you can still read it, you will be impressed what you learn and maybe you will change your mind.

This tutorials will include:

- Programming
- Tips
- Support
- Humour :p
- Theory
- Practics
- Homeworks (I will be checking them)

It would be great if you are at least 14 years old, because if you are younger it is hard to understand all this, but of course you can try.


Ok, relax and let's start.

We are going to learn PHP.

What is PHP? (Wikipedia)

PHP is a scripting language originally designed for producing dynamic web pages. It has evolved to include a command line interface capability and can be used in standalone graphical applications.[2]

While PHP was originally created by Rasmus Lerdorf in 1995, the main implementation of PHP is now produced by The PHP Group and serves as the de facto standard for PHP as there is no formal specification.[3] PHP is free software released under the PHP License, however it is incompatible with the GNU General Public License (GPL), due to restrictions on the usage of the term PHP.[4]



What is PHP (My words)


PHP is a language used to make dynamic website, it means the website will change content without your interact in it.


Because this language is 'Server-sided' it means you need a server to run the scripts, you can't run it from disk.

To do it, install XAMPP, the tutorial how to do it is here:

http://otland.net/f137/all-steps-how-create-forgotten-server-7839/

Only the first few steps!

After installing it, go to your XAMPP folder and open folder: 'htdocs' create new folder there called 'tut' and create new file inside called index.php

To create index.php:
1.Open notepad
2.Go to 'Save as'
3. Sellect 'All Files'
4. Write in 'File name' : 'index.php'
5. Save it in your 'tut' folder (usually: C:\xampp\htdocs\tut)

If you have runned you xampp already (if not read how to do it in tutorial above)
go to your web browser and go to this address:
'localhost/tut' write this in your address box.

You should see blank page, open your index.php from 'tut' folder using notepad and write anything in there, for example 'Hello World!' save it and refresh your page.

You made your first text, simple huh? But that is not even PHP :)

I recommend you to download Notepad++ from here:

SourceForge.net: Notepad++: Downloading ...

This program is better than normal notepad, and it's fast as well, it colorise your code so it's much better to see. You should install it without any problems, now if you want to open your index.php with it, right click on this file and press 'Open with Notepad++' this is the quickest way.

Ok, so let's learn some basics about PHP, the code has to be in speciall code.

So open your index.php and write inside:
PHP:
<?php

and below:

PHP:
?>

As you can see, after refreshing the page you don't see anything, now the PHP code you need to put between those two lines.

For example

PHP:
<?php

Hello World!

?>

Try it!

Yep, after refreshing an error has occured, this is because in PHP there is a lot of rules, you can't just put text to be displayed, but if u put the text before the tags <?php or after ?> it will work.

If you want to display anything through PHP you need to use function called 'echo' to do it.
So between the tags put:

PHP:
echo "Hello World";

You need to use " because this is a text, otherwise if you woudln't use it next error would be shown, as you can see I also added ; at the end, you need to ALWAYS add it after function, otherwise next error would be shown.

Go on, try it.

As you can see you printed text on your website, you can print everything in HTML.

So for example writing this:

PHP:
echo "<title>hello world</title>";

Would work, or this:

echo "<b>Hello world</b>";

so our script looks like this:
<?php

echo "Hello world";

?>

So you experienced few erros, but who gave you the bugs? It's called parser, everytime you refresh the page parser checks if the code is good and there is no mistakes inside, if there is some mistake the parser should tell you where (file) and in which line.

TIP:

If you are writing big code, and you want to disable some part of the code you use comments for it.

For example if you wanna write something above the code:

PHP:
//This shows text on the webstie
echo "Hello World";

In this case, there will be no error, and the text above echo won't be shown because this is a comment and you can see it only in PHP source file.

Comment you declare by adding at the beggining //
Use it only if your comment got no more than a line!

If it has more than a line use this then:

PHP:
/* Some comment
that got more
than a line */
echo "Hello world";

As you can see at the beggining I added /* this declared multi line commend, and don't forget to add */ at the end to tell the script that you finish your comment here.

Now we are going to learn one of the most important things in PHP, Variables!

In variables, you can store data, numeric, strings etc.

You declare variable by using dollar mark: $
name of variable might be any, except speciall chars.

example:

PHP:
$mytext = "Hello world!";

if you write this, you won't see anything in your web browser, but if you write:
PHP:
$mytext = "Hello world!";
echo $mytext;

then echo will show the text from variable 'mytext'
and you will see the text in your web browser.

Also you can give number to your variable example:

PHP:
$mynumber = 1;

There is few types of variables:
Integer
double
string
array
object

but forget about them now, the only one you need now is integer and string.
There is also variables that are unchangable included in PHP core, but I won't tell u them now because it will mix everything. Also there is permanent variables which you can declare, but I won't tell u about them now. :)


Operators:

I'm sure you know them from primary schools:

+ (plus) - (minus) etc.

You can use them in PHP for calculations or other things.

Let's try something :)

First let's declare 2 variables with random numbers:
PHP:
$a = 4;
$b = 3;

So we have 2 variables, a which represents 4 and b which represents 3, let's add them up through PHP.

Let's declare another variable:

PHP:
$sum = $a+$b;

Now, this sum contains number: 7 because 4+3 = 7

also you can use other operators:

+ - adding
- - substracting
* - Multiplaying
/ - Dividing
% - Rest of the dividing.

Go on, try it, i'm sure you know how to display the sum in your web browser.

Here is the full code with comments:

PHP:
<?php

//Declaring variable which is 3
$a = 3;
//Declaring variable which is 2
$b = 2;
//Adding them up
$sum = $a+$b;
//Displaying
echo $sum;

?>

Now let's learn 'if' this is very important in PHP, you can give actions to 'happening'

Let's show it in code.

First we declare some variable:

PHP:
$num = 10;

Now we write the if code.
PHP:
if($num == 10)
{
echo "Yes it works.";
}
else
{
echo "It doesn't work :(";
}

Now, let's explain what we did.

First we declared variable which is 10
then we give 'if'

and if the code in brackets will return TRUE then the code from first {} will be runned, if not then the code from 'else' will be runned.

Operators:

== - If its exactly like this
!= - If it's not like this
< if first variable is smaller than second
> if first variable is bigger than second
<= - if first variable is smaller or same as second
>= - if first variable is bigger or same as second

So, in this code text "Yes it works" will be shown because $num is 10
but if you change $num to something else, for example: 11
then the text "it doesn't work" will be shown.


Also you can add more Ifs

I mean like this:

PHP:
if($num == 10)
{
echo "The num is 10";
}
else if($num == 11)
{
echo "The num is 11";
}
else
{
echo "Sum is other";
}

So if you change $sum to 11 now, then the text from second part will be shown: "The sum is 11"
If 10, then "The sum is 10" if any other then "Sum is other"



END OF PART 1

HOMEWORK FOR U:

Write PHP script for me:

1)
Declare variable with my name inside, and display it on website.

2)
Declare variable with number 5, and if the number is 7 then show text "Doesnt work!"
and if the number is any other then show "I learned something"

Post the code here, I will check it and will give grade and tips.

Also, post commends, and don't be shy to reput me :)
 
great ^^ Keep writing :) Rep++

p.s. :( You must spread some Reputation around before giving it to paxton again.
 
PHP:
<?php
$name = "Paxton";
echo $name;
?>
PHP:
<?php
$a = 5;
if ($a == 7)
{
echo "Doesn't work, and I didn't learn anything.";
}
else if ($a != 7)
{
echo "I guess I learned something";
}
?>
xD Liked it, but hopefully your future ones will be alot more advanced then this :(
 
PHP:
<?php
$name = "Paxton";
echo $name;
?>
PHP:
<?php
$a = 5;
if ($a == 7)
{
echo "Doesn't work, and I didn't learn anything.";
}
else if ($a != 7)
{
echo "I guess I learned something";
}
?>
xD Liked it, but hopefully your future ones will be alot more advanced then this :(

Grade: A*

Yes, they will be :)
 
Nice tutorial for beginners. But please tab your codes correctly:p. Else you teach them to code bad menz. rep+
 
1.

PHP:
<?PHP
$text = "Paxton";
echo "Hello $text";
?>

2.
PHP:
<?PHP

$num = 5;

if ($num == 7)
{
	echo '<font color="red"><b>Doesnt work</b></font>';
}
elseif ($num != 7)
{
	echo '<font color="red"><b>I learned something</b></font>';
}
	
?>
I want to know how to use math.random..:)




We should send our homeworks PM to you.. otherwise we can just copy from other:p ;)

@edit

with random
PHP:
<?PHP

$num = rand(6, 7);

if ($num == 7)
{
	echo '<font color="red"><b>Doesnt work</b></font>';
}
elseif ($num != 7)
{
	echo '<font color="red"><b>I learned something</b></font>';
}
	
?>
 
Last edited:
PHP:
<?PHP

$num = rand(6, 7);

if ($num == 7)
{
    echo '<font color="red"><b>Doesnt work</b></font>';
}
else
{
    echo '<font color="red"><b>I learned something</b></font>';
}
    
?>
 
PHP:
<?php
//Text on Website
$text = "Paxton";
$text2 = "<br>Make another tutorial :D<br>";
echo $text,$text2;
?>

PHP:
<?php
// Variable is 5
$num = 5;
if ($num == 7)
{
//Showed text if $num is correct
echo "I learned something";
}
elseif($num != 7)
{
//Showed text if $num is incorrect
echo "Doesnt work!";
}
?>

I hope you will soon School part 2 :p
 
Both of you right, well done :)

Be patient for more advanced level, you need just wait, in some others parts we will be doing sockets etc, so it won't be that easy :)

btw: 16 points needed for next rep square ;)
 
First

PHP:
<?php
$mytext = "Hello Paxton, you rock!";
echo $mytext;
?>

Second

PHP:
<?php

$a= 3;
$b= 6;
$sum = $a*$b;
echo $sum;
if($num == 18;
{
echo "I learned something";

else if($num == 11)
{
echo "Doesnt work";
?>

I am not so sure about this, but I did my best :D had all memorised so might be a little bit weird but hope it works! :p
 
First

PHP:
<?php
$mytext = "Hello Paxton, you rock!";
echo $mytext;
?>

Second

PHP:
<?php

$a= 3;
$b= 6;
$sum = $a*$b;
echo $sum;
if($num == 18)
{
echo "I learned something";
}
else if($num == 11)
{
echo "Doesnt work";
}
?>

I am not so sure about this, but I did my best :D had all memorised so might be a little bit weird but hope it works! :p
U forgot about brackets :p

Now go to Part 2 :)
http://otland.net/f139/paxtons-web-development-school-part-2-a-29066/
 
Back
Top