Sunday, December 20, 2009

Install WAMP server

The WAMP server is one of the most important, easy to install and successful tool in making up the most of the free features. Also helps to learn PHP and can be used as a building stone.

WAMP server can be downloaded from http://www.wampserver.com/en/download.php and installed as per the directions.

On Installation , you can specify a directory as C:/WAMP for installation path, so that people using VISTA dont have to struggle with Admin rights each time , as is the case if installed in Program Files. Its just a suggestion and you may use any method you want.

Once the installation is completed, open the default internet browser , and type http://localhost or http://localhost:80

WAMP homepage should come up.

In case the WAMP homepage is missing, check the system tray for WAMP icon , right click and select "PUT ONLINE" , or an option that appears to be like that (like start all services) .

Once the homepage displays (http://localhost) WAMP server , WAMP is ready and you are ready to go for your PHP code

Wednesday, June 10, 2009

Interview Questions And Answers in PHP

1. What are the differences between Get and post methods in form submitting, give the case where we can use get and we can use post methods?

Ans: Using HTML we use form to submit the values. Click here to know more about HTML forms. Get is used to pass the data using URL , and we can send a particular length of characters as supported by the explorer.
When we use POST method , we can send the unlimited length of data using POST.

Action is used to submit the form , and the elements in the form get in array as $_POST, $_GET and $_REQUEST

Tuesday, April 7, 2009

Operators in PHP

Just like any other programing language , PHP comes with its own set of operators. they might look similar to behave in same way as any java or c# operator. But we will look into the operators as they might be some variations. There are different types of operators in PHP : 
  1. Arithematic operators
  2. Assignment operators
  3. comparison operators 
  4. Logical operators 
Arithermatic operators : Throughout the history , the first things we learned we learned were alphabets and numbers. Then we have added ages to the life, subtracted the shortcomings ,and multipliedz our experience in life. All these operations in PHP are carried with a rich set of arithematic tools it has to offer. Below is a table which lists the various PHP operators : 

Operator

Description

Example

Result

+

Addition

$iknowjavaAdd=2
$iknowjavaAdd+20

22

-

Subtraction

$iknowjavaSub=29
$50-
iknowjavaAdd

21

*

Multiplication

$iknowjavaMultiply=54

$iknowjavaMultiply*2

108

/

Division

15/5
5/2

3
2.5

%

Modulus (division remainder)

5%2
10%8
10%2

1
2
0

++

Increment

$iknowjavaInc=59

$iknowjavaMultiply++

x=60

--

Decrement

$iknowjavaDec=90

$iknowjavaDec--

x=89


----------------------------------------------------------------------------------------------------------------------------------------
Assignment operators 
----------------------------------------------------------------------------------------------------------------------------------------
Assignment operators : Many times we have looked into assignement operators. This is a new beginning for many. If i want to put a value of 5 in a variable $iknowmyjava, then I will have to find a way to do it. I will use "=" sign . 
Such type of operations are handled by assignment operators. A few PHP operators are listed below : 

Operator

Example

Is The Same As

=

$x=$y

$x=$y

+=

$x+=$y

$x=$x+$y

-=

$x-=$y

$x=$x-$y

*=

$x*=$y

$x=$x*$y

/=

$x/=$y

$x=$x/$y

%=

$x%=$y

$x=$x%$y


----------------------------------------------------------------------------------------------------------------------------------------
Comparison operators 
----------------------------------------------------------------------------------------------------------------------------------------

Operator

Description

Example

==

is equal to

5==8 returns false

!=

is not equal

15!=18 returns true

> 

is greater than

15>18 returns false

< 

is less than

51<81>

>=

is greater than or equal to

51>=81 returns false

<=

is less than or equal to

51<=81 returns true


----------------------------------------------------------------------------------------------------------------------------------------
Logical operators 
----------------------------------------------------------------------------------------------------------------------------------------

Operator

Description

E$xample

&&

and

$x=6
$y=3

($x <> 1) returns true

||

or

$x=6
$y=3

($x==5 || $y==5) returns false

!

not

$x=6
$y=3

!($x==$y) returns true

Monday, April 6, 2009

Data Storage in PHP

Data is stored in variables in any programing language. The variables declared in PHP are a bit different than other programing languages. Each variable name starts with "$" sign. If I like to name a variable as iknowPHP variable , it will throw an error. 
The way to declare a variable in PHP is simple though.
$iknowjava = 5;
$iknowmyjava ="Deepak";

Few points : 
  1.  Variable name can start with $ only
  2. Variable name can have only alphabets or numbers or underscore or combinatiion of these three. Spaces in variable names are not permitted
 Once done with the variables , PHP will itself decide on what variable it is , whether its a string variable , a char or a number , depending on the value it has. 

So we will move to next important part in PHP , the various operators.

Writing the first Code

Now we are well set to make the first program. Or the web application. Lets start. 
Go to Location :
C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs 

Or find the folder named htdocs in Apache installation folder. 

Open the text editor / Textpad. 
This can be done by right clicking in any folder --> New --> Text File.

Now write the following code in the the notepad: 

Save this File as iknowPHP.php in the HTMLDOCS folder in Apache. 
Make sure you have not saved it as iknowPHP.php.txt  . 
Run the script . How to do that :

Running the first script: 
Open IE and type :
If the page says  : It works , then we are right into running the first script. Just append the address with iknowPHP.php and hit enter
http://localhost/iknowPHP.php

The script should run. In case the explorer asks to save the file , then please go through installation steps once more for correct installation. 
Do visit www.iknowjava.com for more codes in PHP / JAVA and C#




Thursday, February 26, 2009

Configuring The Apache Web server to PHP

Now we want to configure the apache web server to the php so that we will be able to use this code for developement of the code locally. 
First step is to type 
http://localhost on the web browser. 

Now Go to Server directory , which is in C:/Program folders / Apache .
Now if you have app servers installed , these will also be located in the same folder, make sure u select the web server ( version 2.2) and not tomcat . 

Now go to Conf folder and locate the file httpd.conf 

Open the file and search for "#LoadModule" . Once you find the LoadModule, append the last line in the same para with the following value :
"#LoadModule php5_module c:/php5apache2_2.dll" 

Now search for "AddType" and add 
"AddType application/x-httpd-php .php"

restart server :)

Saturday, January 24, 2009

Chapter 2.2 - Verifying Installed Apache

Now we need to checke whether Apache is running or not.  There are two ways to verify whether the Apache is installed. 
 Go to Start -> and types services.msc in Run prompt .  Select the services as shown.


Once Service is selected , there is a process named Apache2.2 listed. If you can see the process , then Apache is installed. If its running successfully , just double click the Apache2.2 . You will get the pop up

Click on Start . If the service is changed to Started , as shown below , Start will become disabled , and Services will be started. 
Congratulations . Apache is installed on the system. 

Second Way to Use and Verify Apache 

Go to Programs ,  navigate to Apache 2.2 and click the selected server.
An  icon appears in the taskbar as shown. Double click on it . 
 
The dialog box opens. Click on Start , and if its running , Congratulations , your APACHE Web Server is installed 

Once we are done with the Apache installation , we need to verify its working .