Nikkster
Programmer
Hi there and welcome to my tutorial. This course will focus on the programming language 'PHP' which stands for "Hypertext Preprocessor". I assume you have seen me making C lessons before.
Why?
After some reading in the web application forum, I found that quite many does not have a clue of what they are doing.
FAQ:
Do I need any preknowledge?
Basic knowledge about HTML/CSS and javascript, should do it. Although, it is not necessary.
I already know C/C++, will it be easier for me to learn PHP?
If you know C, you know PHP. Having a quick look at PHP's structure might be a good idea, though.
Now, create a new file with the extension .php. We'll call it "example.php". Open up the file with a texteditor, I recommend "notepad ++" or "Aptana Studio".
What we're doing here is, we always start our codes with either <? or <?php (depending on PHP version) and finish the code with ?>. Then, we write a simple variable and defines it. Then we echo or "print" the text inside the variable on the webpage. You can also do it in other ways, of course.
To see the results of our new code, start the webserver and go to localhost/example.php. The text "Hello World" should appear on the white background in a black text.
Creating comments in PHP is as simple as writing // this is a PHP comment.
Example:
If you have any questions, please post in this thread. Also, post what you think about this tutorial. In the next tutorial, we'll be going for more in-depth about PHP. Although, I will try to go through the most basics first, and then we can go for sessions, cookies, $_POST, if-statements, $_GET, etc.
We will also be discussing security "mysql_real_escape_string". We will talk more about this later.
Why?
After some reading in the web application forum, I found that quite many does not have a clue of what they are doing.
FAQ:
Do I need any preknowledge?
Basic knowledge about HTML/CSS and javascript, should do it. Although, it is not necessary.
I already know C/C++, will it be easier for me to learn PHP?
If you know C, you know PHP. Having a quick look at PHP's structure might be a good idea, though.
INTRO
PHP is used to create dynamical content on the website and communicate with a database, (MySQL).CREATING YOUR FIRST PHP CODE
First you will need a webserver. I recommend XAMPP (LAMPP). If you have IIS, it works also. Now, create a new file with the extension .php. We'll call it "example.php". Open up the file with a texteditor, I recommend "notepad ++" or "Aptana Studio".
PHP:
<?php
$variable = 'Hello World';
echo $variable;
?>
What we're doing here is, we always start our codes with either <? or <?php (depending on PHP version) and finish the code with ?>. Then, we write a simple variable and defines it. Then we echo or "print" the text inside the variable on the webpage. You can also do it in other ways, of course.
PHP:
<?php
echo 'Hello World';
?>
COMMENTS
As in all other programming languages, it works to create comments in PHP, which can be good if you are working on big projects. Creating comments in PHP is as simple as writing // this is a PHP comment.
Example:
PHP:
// this is a comment in PHP
If you have any questions, please post in this thread. Also, post what you think about this tutorial. In the next tutorial, we'll be going for more in-depth about PHP. Although, I will try to go through the most basics first, and then we can go for sessions, cookies, $_POST, if-statements, $_GET, etc.
We will also be discussing security "mysql_real_escape_string". We will talk more about this later.