PHP & MySQL Tutorial – Part 1

No Comments

The first Article of this series was called Part 0.5 since that it didn’t discuss PHP. And somehow it was catchyJ.

In this article we will start little bit with PHP coding, but before that we need to discuss something very important. Please follow the below to the end, and later on you will get the full image. (Just be patient, and try to follow things step by step).

In the last article you had created one file called index.hml. Get that page loaded again by using your browser, and going to http://localhost/ . (Note: Make Sure that WAMP is running!).

In the Internet Explorer Page, right click and then click “View Source”.

There you would see the HTML codes of the page.

<html><head>

<meta http-equiv=Content-Type content=”text/html; charset=windows-1252″>

<meta name=Generator content=”Microsoft Word 14 (filtered)”>

<p class=MsoNormal>Hello World !!</p>

</body>

</html>

Note: If you applied any formatting on the Hello World, you will see more codes over there. The common thing is that you would see Hello World!!.

Where That Came From?
Well, Microsoft Office Took care of generating that code for you. You can see that somewhere within those codes, you Hello World!! Does exist.

 

Fine, I need you to do one more thing, which is opening the index.html using note pad. You will find that the same HTML codes are over there.

PHP way!

Now, open Notepad (StartàProgramsàAccessoriesàNotepad)

Write the below over there:

<html><head>

<body>

<?php echo(“Hello World!!”); ?>

</body>

</html>

Save the file as index.php, and copy that file to c:\wamp\www directory.

Note: Delete index.html please!

 

Now, using Internet Explorer; go again to http://localhost/

Again, right click, and View Source. Below HTML code will be shown:

<html> <head> <body> Hello World!! </body> </html>

 

Remember now, you wrote something in your php file saying echo, right?

But here you cannot see it!! Where has that gone! Well, your server had translated that into HTML !.

Now, remember the below; since this will remain with you for the rest of your life as a PHP programmer!

PHP script is inserted between thestart up tag <?php

and the closing tag ?>

Ex: <?php echo(“Hello World”); ?>

You web page should include at least the following HTML codes (It can work without them, but results are not guaranteed!).<html>

<head>

<body>

</body>

</html>

Contents of the webpage will be placed between <body> and </body> tags.

 

<? Can be used instead of <?php as a short form. (But this will require some modification which we will carry on in the next tutorial (Well, I need to keep you excited for the next one, right?)

 

echo is the first PHP function that you had used. It’s used to print out whatever entered between the parenthesis.

Example: echo(“I am an PHP Programmer”); à will display è I am an PHP Programmer

 

Don’t forget the semi colon at the end of every PHP command.

 

What Had Happened!

Please read the below carefully, and it’s ok to read it twice or trice! The below is really important to grasp at this stage, thus things will be clear forever. (Ok not everything will be clear, we are just talking about PHP and coding; don’t expect this to make behavior of crazy and psycho people you meet in life clear!).

When you entered http://localhost/ in you browser and Enter was hit, your browser sent a request to fetch the index page located in the localhost server. (Which is your PC that is running Apache server!)

(Note: If you don’t know what Server means, please do some googling, that’s what google was made for!)

Apache server will find that the index page is in PHP format (remember; you saved the file as index.php)

The server will not pass the index file as it is this time (Not like what happened when we had index.html). The server will process the php file, and generate the HTML codes based on the PHP codes existing in your PHP file. (In this case, the output of <?php echo(“Hello World!!”); ?> was Hello World!!

The HTML codes will be sent to your browser.

FIN!.

 

Ok, I hope that you were not expecting to have a webpage similar to google.com from the second tutorial; the journey is still long, and a lot of hard work to be carried out! Wait for the next tutorials, and please feel free to contact me if you have any questions or suggestions.

Leave a Reply

Your email address will not be published. Required fields are marked *