Tag-Archive for » start php «

Start taking Taste of Web development with PHP

 

Taste of Web development using PHP

 Well at this stage, we know how to setup PHP, MySql and Apache. We have installed either XAMP or WAMP (ready made package of PHP, MySql and Apache). Moreover we run a simple PHP script hello_world.php. Which means now we are able to create a project, write php code and run it in browser.

Lets move forward with a simple page with some HTML controls. Lets define our requirement first.

It’s a member information page with the following fields: first name, last name, email, contact no, present address and sex. When we enter data and submit this page it will goes to another page and shows the information. That’s all for today.

Lets start. Our first task is to create a simple page member_info.php. Now lets add the fields first name, last name, email, contact no, present address and sex. Before write a single line of code we have to think first, which HTML fields we will use. For first name, last name, email address it’s fair to choice text box. Moreover, for present address wise to select text area as though address need multiple line of input. Lastly, for sex it’s clever decision to choose radio button with predefined values Male and Female. So here is our page member_information.php.

 

Untitled Document

Welcome to Member Information Page
First name
Last Name
Email
Address
Sex Male

Female

 

Now when you browse this page (like: http://localhost/project_name/member_information.php ) you will get all fields of your page. When you enter some informations and press submit the page goes to http://localhost/project_name/success.php. Lets clarify how is it works. if you observe this page closely you found

//some html controls.. text box, radio button and submit button


A submit button is fully responsible to submit the page to server along with all inputed informations. And form action=”success.php” define where these informations will be submitted. As a result it submits to success.php. Hey!!! It shows you No page Found 404 Error Right? Don’t worry. You are correct. Just make sure your URL (at address bar) end with success.php.

Well at second step. lets build success.php. This is a simple page where we show all data inputed at member_information.php. Here is the code of success.php

Untitled Document

Welcome to Member Information Page
First name
Last Name
Email
Address
Sex

So you get your inputed data. right? Right now you url in address bar is http://localhost/project_name/success.php Lets analyze success.php. Actually we use here $_POST['field_name'] to display any field_name value. By example, we have

which means address is a HTML field what is submitted to success.php through a POST method. Lets remind our mind we have

in member_information.php page.

that’s all for today. Try yourself to understand how this page is working. test by add some fields like phone number in member_information.php page and display it at success.php.

Best of luck :)

How to start PHP

Before start php you need some back understanding of web technology. How web sites are developed?

Web site consist of three parts. We need to understand clearly what these are and how it works. First of all you need a server called web server. Apache is a server of linux where you actually put your files. Secondly you need to choose a scripting language. Without any scripting language you site can’t be dynamic. We choose PHP as web language. Finally to handle operations of data you need a database. Mysql is best suited with PHP and Apache.

LAMP: Stands for Linux, Apache, Mysql and PHP. So we can easily understands that, PHP is best suited in Linux server and this is the reason why everybody chooce Linux server for hosting. In contrast, most of we are using windows. Moreover, configure LAMP is not so easy for everyone. So what’s the solution? There are a number of integrated tools which are simple to install and configure automatically. XAMP is a very good one. WAMP is another one. You can download both for free from the web. Download XAMP/WAMP anyone  you like and compatible with your OS. Once XAMP/WAMP download and installed you are ready for to code with PHP, MySql and Apache.

For instance lets download and install XAMP. Then goto c://xamp/htdocs/ this is called root/document root. Lets create our first project named practice

create a folder c://xamp/htdocs/practice named practice.
now create a file named hello_world.php inside practice folder. i.e c://xamp/htdocs/practice/hello_world.php
Web consist of HTML/XHTML , Scripting language(PHP, C# dot net, JSP, Cold Fusio etc), Javascript and Database.
PHP code must contain a beginning and ending tag.
Short tag: <? …… ?>
Full tag: <?php …… ?>
Paste following code into hello_world.php file
<?php
echo “hello world”;
?>
How to run your script/site? Open a new browser window(Mozilla firefox or Internet explorer or Google Chrome) and paste the following url into your address bar.
where practice = project name
hello_world.php = file name.