Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Tuesday, 8 April 2014

Calculate NET SALARY of employees in php


Calculate NET SALARY of employees using following criteria In Php.

If basic salary is greater than 10,000 then

  • Dearness allowance (DA) =5% of basic salary
  • House Rent Allowance (HRA)= 5% of basic salary
  • Provident Fund (Pf) =2% of basic salary
If basic salary is greater than 25,000 then
  • Dearness allowance (DA) = 10%  of basic salary
  • House Rent Allowance (HRA) = 10% of  basic salary
  •  Provident Fund (Pf) = 10% of basic salary
If basic salary is greater than 50,000 the
  • Dearness allowance (DA) = 15%  of basic salary
  • House Rent Allowance (HRA) = 15% of  basic salary
  •  Provident Fund (Pf) = 15% of basic salary

Code For Calculate Net Basic Salary


<html>

 <body>

 <form name="frm1" method="GET" action=""> // Basic Html Form

 BASIC SALARY:<input type="text" name="bs"> // Input Textbox for take value to calculate

 <br>

 <input type="submit" name="submit" value="submit"> // Submit value for calculate

 </form>

 <?php

 $page=$_GET['frm1']; //to get a value from the html form

 if($page="frm1")

 {

 $bsal=$_GET['bs']; // to get value of textbox



if($bsal>=10000) // If basic salary is greater than 10,000 then



{

 $da=0.05*$bsal;

 $hra=0.05*$bsal;

 $pf=0.02*$bsal;

 $ns=$bsal+$da+$hra-$pf;

 echo("net salary is $ns");

 }

 else if ($bsal>=25000) // If basic salary is greater than 25,000 then

 {

 $da=0.1*$bsal;

 $hra=0.1*$bsal;

 $pf=0.1*$bsal;

 $ns=$bsal+$da+$hra-$pf;

 echo("net salary is $ns");

 }

 else if($bsal>=50000) //If basic salary is greater than 50,000 then



{

 $da=0.15*$bsal;

 $hra=0.15*$bsal;

 $pf=0.15*$bsal;

 $ns=$bsal+$da+$hra-$pf;

 echo("net salary is $ns");

 }

 else

 {

 $da=0;

 $hra=0;

 $pf=0;

 $ns=$bsal+$da+$hra-$pf;

 echo("net salary is $ns");

 }



}

 ?>

Read More

Saturday, 5 April 2014

Calculator In PHP

Calculator in php Script
Calculator In Php

Php Code For making calculator In Php Which will perform functions such as addition,subtraction,Multiplication,Division.






Code For Calculator In Php


<?php

//The following is the calculator code:



ini_set('display_errors',0); //ini_set for error reporting

if( isset( $_REQUEST['calculate'] ))//isset check whether value is null or not.

{

$operator=$_REQUEST['operator'];

if($operator=="+")// add operator

{

$add1 = $_REQUEST['fvalue']; // getting values of html form

$add2 = $_REQUEST['lvalue']; // getting values of html form

$res= $add1+$add2;//adding values

}

if($operator=="-")//substracting operator

{

$add1 = $_REQUEST['fvalue'];// getting values of html form

$add2 = $_REQUEST['lvalue'];// getting values of html form

$res= $add1-$add2;//substracting values

}

if($operator=="*")//multipilcation operator

{

$add1 = $_REQUEST['fvalue'];//  getting values of html form

$add2 = $_REQUEST['lvalue'];//  getting values of html form

$res =$add1*$add2;//multiply values

}

if($operator=="/")//divide opeartor

{

$add1 = $_REQUEST['fvalue']; // getting values of html form

$add2 = $_REQUEST['lvalue']; //  getting values of html form

$res= $add1/$add2;divide values

}



}

?>

<form> // html form

Enter First Number<input name="fvalue" type="text">

            Select Operator <select name="operator">

<option>+</option>

<option>-</option>

<option>*</option>

<option>/</option>

</select>

Enter Second Number<input name="lvalue" type="text"/>

<input type="submit" name="calculate" value="Calculate" />

                Output =

               <?php echo $res;?>// output results

 </form>


Output Screenshot1

Calculator In Php
Screenshot1
In this example i had made calculator to calculate two values for addition, subtraction, Multiplication, Division.

Refer Articles :-
Articles For Detail Study Programming In Php. Details About Php Code Which I used to make Calculator In php. 
Read More

Friday, 28 March 2014

Explode function with file handling example

php explode implode function
The explode function with file handling example in php programming language. Will read the file. echo out to the user for reading the data of the file by file handling in php programming language.

Code for explode function with file handling example(Screenshot1)

explode function file handling php
Screenshot1

<?php



$filename = 'names.txt';

$handle = fopen($filename,'r');



$datain = fread($handle, filesize($filename));



$names_array = explode(',', $datain);



foreach($names_array as $name) {

echo $name. '<br>';

}



?>

Output (Screenshot2,)

php explode function
Screenshot2
In this example we are going to learn to read data from a file but obviously when u are reading data from the file. Its not always line by line basis. You may find commas separating your values and in this case we got few names here commas separated each value. Now how we deal with reading this in. Php file handling reading into the file. 

$handle fopen($filename, 'r');

Above code will create a handle to open and reading the file r stands for reading the file. We can also use file function which i had shown in example of file handling reading to the file. or we can also write  $handle fopen('names.txt','r');. I have taken names.txt in variale $filename for futhur use.

$datain = fread($handle, filesize($filename));

Above code will inilize the filesize will tell php file contain that much data instead of writing filesize we can also write the character we want from the file. like fread($handle,100); that's means it will contain 100 characters from the file.


$names_array = explode(',', $datain);

It will explode all commas from the file. Will remove commas from the file array of the name.

foreach($names_array as $name) {
echo $name. '<br>';
}

It will get array will write names one by one.
Read More

Wednesday, 26 March 2014

Creating Cookies with php

Creating Cookies with php programming Language. You may be seen cookies may be in your browser setting. I am Sure every one know What is Cookies are but how we actually use them and how useful are there in every day programming on websites. A cookies is a piece of data or a file that stored specific information and its unique to you and the website that you viewing. So, If you view on your browser a website that set a specific cookies and you access to that website depending on the expiration time cookies that piece of data will be relate. That will be relate to your computer to the website. So, This way website can store data about users or about your specific preferences on in there website and it can be stored on your computer for later access.


How we can go about setting cookies and why they useful now there are some of the reason why they are useful for is just storing data that's need to be used to be later day for long expression time. You may already seen my article setting session in php. Cookies again allow you to set a much longer expression date. So, sessions are  close as soon as your is close in the connection is short in the server. However with cookies we could store cookies for year.


Code for Creating Cookies With php 

Set.php (Screenshot1)

setcookie
set.php Screenshot1

<?php



setcookie('username','alex','time()+10')



?>

View.php (Screenshot2)

cookies with php
Screenshot2


<?php



echo $_COOKIE['username'];



?>

Output 

cookie php
Screenshot3
cookies in php
Screenshot4
view cookie php
Screenshot5
To set cookies we use setcookie function takes few arguments. Here i will show you few arguments. I will go through three main arguments and three main arguments we look at first one is the cookies name you are setting then the value of cookies want to store in the cookies and the expression date. The time in which the cookies going to be valid for. Now remember when we look at sessions we write like $_SESSION['name']='value'; and in Cookies we write like setcookie('name','value','time');. Here in this example i had set cookies in set.php with setcookie function with arguments name is username value is alex and the expression time is something that how much time we want to put for the cookie exit to the browser. Its value of time expression is in seconds. For set the time expression argument we need to use timestamps infact in every php when we need to use date time function we need timestamps to retrieve date time etc. 

If you don't know what is timestamps please read articles of Extra Tutorials on timestamps. Timestamps in php is basically around of seconds current day in seconds. So, We use time function to grap a timestamps. So, Here we had time() which will retrieve current time then we add more 10 seconds to delay the cookies.

Now in view.php i had echo out the viewing the cookies and you can see after 10 seconds cookies will be expired. After refresh output you can see how cookies had been expired. Because timestamps gone less then the current time. 

So, You can Use cookies in login system where you want to your user can access logged time interval after that you want to logout the user. So, How basically cookies are useful but remember cookies are stored on users computer. So, There are dangers to use things like sensitive data that you don't want to user to change for example you had a shopping card and you have total set in cookies.  You don't necessary want this unless you using some form of encryption some database used to store that information can be stored to the user computer and that can harm websites. 

Code for Unset Cookies with php

Set.php 




<?php



setcookie('username','alex','time()-10')



?>

View.php (Screenshot2)

Screenshot


unset cookies
Screenshot2
 Now For Unsetting the cookies there is not any function for unset or make sure cookies file must delete from the users computer is to subtract the seconds of the cookies. Now If you will set the cookies it will not set because it is unset. Now why you need to unset the cookies or what is need to unset the cookies we answers quite simple login system if you log you user storing file where they logged in cookies and you may be log in for 1000 seconds if you want to log them out you may have logout button now when i click logout button we need some way insuring that cookies is deleted and unset so, users no longer logged in so obviously clicking logout button we perform some kind of operation like subtrating seconds from timestamps to ansure that the cookies had unset and the users no longer logged in. So, thats the simple example for unset the cookies and that basically simple way.

Read More

Wednesday, 19 March 2014

Using the Header function to Force Page Redirect

using header function to force page redirect
Using the header function to force page redirect in php programming language. In this we are using header function in php. So, if we want to modify header which sends to our browser. Now why we need to modify header which are sends to our browser. Now there are lots of reason for this like enable or disable caching of pages you also may want to change document type you may want to change like to jpeg or png images something like that. In order to process image on page if you are using php gd library. We use header function to redirect our users to another page.

Code for using header function to force page redirect (Screenshot1) :-

Using the Header function to Force Page Redirect
Code For Using Header Function To Force Page Redirect Screenshot1



<?php

$redirect_page = 'http://google.co.uk';

$redirect = true;



header('Location: '.$redirect_page);



?>

Output (Screenshot2) :-

Using the Header function to Force Page Redirect
Output Screenshot2
In this example i am creating variable called $redirect which will be going to true.  I want to do that if this variable is true then redirect page to other page like example http://google.co.in. This type of functions you can also use when you want to redirect users to specific page like users sign in or sign out you want to redirect them to specific pages. So, we declare header function inside that we specify location which had predefined text 'location:' after that the page we want to redirect now there are two ways to declare location one is header('Location: http://google.co.uk'); or header('Location:'.$variable_name); variable name is the name of the variable in which we had stored the path of the redirect file here we had variable $redirect_page. As we refresh this file it will redirect us to http://google.co.in. 

Now you can see how its useful to redirecting pages to another page. If you will see my further article you may come to know that this function is not only used for redirect its just used to modify header information your client or your browser. Location feature is very important. Its a quickly way to redirect the user without using any html meta tags. 

Code for using header function to force page redirect (Screenshot3):-

code for using header function to force page redirect
Code for Using Header Function to Force page Redirect Screenshot3


<h1>My page</h1>

<?php

$redirect_page = 'http://google.co.uk';

$redirect = true;



header('Location: '.$redirect_page);



?>

output (Screenshot4):-

header function php
Output Screenshot4
As you can see in this example is the same example of header function which is in screenshot1. But in this code we had declare h1 tags before header function its importance to notice in header functions if data is passed to browser it will not work to redirect. header function must be declare first or other wise we can use ob_start in php article which is stands for output buffering. You can see screenshot4 of warning. 

But if we declare h1 tag after the header function it will redirect the page. but you will not gonna see that h1 tag because it will redirect the page. 
Read More

Friday, 28 February 2014

Functions with Arguments in php

call by reference
Functions With Arguments in Php Programming Languages. This tutorial is about functions passing arguments to functions.Functions are useful in code to shorten the amount of code to write and you can refer back this functions too which is known as calling of functions and it will process the same code every-time you call.

Code basic Structure of functions (Screenshot1):-

Functions With Arguments In php
Screenshot1

<?php



function name() {

   /// here

}



name();



?>


This is basic and standard structure of functions.

Code for adding numbers by functions (Screenshot2):-

Code for adding numbers by Functions Screenshot2

<?php
function add($number1, $number2) {
echo $number1 + $number2;
}
add();


?>

In this example,I have created a function adding two numbers.You may do programming as it is simply done to add two numbers. You may take user input as number1 and number2 and for that you may need functions to add to numbers together. Always get practiced of using functions instead of structures as its lot better then doing things on the fly. By calling functions specially with arguments you save a lot of time,better and as well as easier to read.
In this example, I am making function add and inside the function specify those arguments which are in the form of variables.Here my variables are $number1 and $number2. Here the variables type are unspecified that whether they are numbers or string which actually doesn't matter.That depends on how you deals everything inside functions.Now echo out that particular results where $number1 will refer to functions variable. The functional arguments must match that is used in the functions. Here let me show you calling functions without arguments to show you errors, and how to read errors.
In output Screenshot3
Now you can see in output warning coming up which is missing argument 1 for add(). Its telling us first argument is missing for function add, it tells us in which line code is and it also tell us where the functions has been declared. And also its missing argument 2 for add() function and code in same line and function is defined in same line and actually it gives the results.

Code for adding two numbers in functions with arguments(Screenshot4):-

Code for adding two numbers in functions with arguments Screenshot4
<?php



$inumber1 = 10;

$inumber2 = 5;



function add($number1, $number2) {

echo $number1 + $number2;

}



add($inumber1,$inumber2);

?>

Output (Screenshot5):-

Functions with arguments in php
Screenshot5
In this example of adding two number we are including some numbers. Taking two variables like inumber1 and inumber2. Now as we created variables $number1= 10 and $number2= 5 so, result is 15.Now when we call function we need to specify that two variables ,this two variables will pass as $inumber1 will be pass through function variable $number1 and $inumber2 will be pass through function variable $number2. That the only arguments we need to pass through functions.Now calling in add() that variables will be interpreted, then inside functions they are processed.then we echo out the results.And you can see results 15.

Code for adding two numbers in functions with arguments(Screenshot6):-

Screenshot6
<?php



$inumber1 = 22;

$inumber2 = 8;



function add($number1, $number2) {

echo $number1 + $number2;

}



add($inumber1,$inumber2);

?>

Output (Screenshot7):-

functions with arguments in php
Screenshot7
In this examples codes are same just changed variables to different integer.

Code for functions with arguments to display date (Screenshot8):-

functions php
Screenshot8
<?php



function displayDate($day, $date, $year) {

echo $day.' '.$date.' '.$year;

}



displayDate('Monday',31,2011);



?>


Output (Screenshot9):-

arguments in php functions
Screenshot10


In this example,I am making functions to print date.Making functions of displaying date will feed in the day , the date and the year.Then echo out the result into the functions.Here our day will be string then date will be integer and year will be integer.Now on calling the function displayDate(), passing variables string as well as integer will be displayed.In this way arguments can be pass in php.
Read More

Basic Functions in php

Functions in php
Basic Functions in PHP Programming Languages. This tutorial is for Basic Functions. Why functions are useful in php and also in other programming languages? Lets see how we can create functions and use a function with our page. Firstly let me know you a function is something which allows you to declare a block of code that we may want to reuse,we use more arguments which is sometimes refractive.

Code for basic structure for functions(Screenshot1):-

Basic Functions In Php
Code for Basic Structure for Functions In Php Screenshot1

<?php



function MyName() {

echo 'Mohammed';

}



echo 'My name is <br>';

MyName();

?>

Output (Screenshot2):-

Basic function in php
Screenshot2
In this examples of basic structure of functions there is keyword “function” along with name of function i.e “MyName” and conditions in curly brackets. Since this example is basic so I am just showing you to echo out my name using functions. Then when we want to use functions we just had to call the function by name and conditions inside curly brackets are applied.
Now you need to think about it logically how you can use functions in your programs.
Read More

Thursday, 27 February 2014

Do While Loops In Php

This tutorial is for Do While Loop.Now we had looked while loops that basically count to 10 and prints hello each time it is incremented. Do while loop is very similar to while loop,only a minor difference is that we don’t check whether condition is true or false or we don’t evaluate condition in start. Do while loop always runs the loop once.

Code for Do While Loop (Screenshot1):-

Do While Loops
Screenshot1

Output Screenshot2

Do While Loops In Php
Screenshot2
In this example we are using “do” keyword that will not check conditions but will perform whatever we tell to do and after that in while loop it will check condition. In above example, we have echo out in do loop “This will ALWAYS show” and in while statement we have false that condition.

Code for Do while loop (Screenshot3):-

Do while loops
Code for do while loops Screensot3

Output (Screenshot4):-

Screenshot4
In this example we are doing same thing as we did in while loops Examples .In this we are echoing out “This will ALWAYS show” 10 times where we set counter to start with value 1 and incremented it up-to value 10. If while loop condition get false it will always echo it out once by do loop. The main aim of using Do While Loop is that as it name refers it will first echo out once any statement/process declared inside “do statement” and only after executing that part it will move for executing “do statement” further on the basis of declared conditions in “while statement”.
Read More

Wednesday, 26 February 2014

While Loops in php

This tutorial is of While Loops. In php,why we need loops during programming ? Here we may repeat certain amount of actions for a specified amount of times.

 Code for While Loop (Screenshot1):-

While Loops in php
Screenshot1

Output (Screenshot2) :-

while php
Screenshot2


In this example we have echoed out “Hello” by while loop.In this loop 1 evaluates true which echo out “Hello” but what if we want to echo out “Hello” 100 times! Let see example,how to echo out “Hello” for 10 times.

Code for While Loop (Screenshot3):-

Code for while loops in php
Code for while Loops Screenshot3

Output (Screenshot4):-

php while code
Screenshot4
In this example, we have starter counter which initialize/starts loop and condition counter which must be less than or equal to 10 that will be incremented again and again upto the limit of condition counter and thus echo out “Hello” 10 times.

Code for While loop (Screenshot5):-

While Loops
Screenshot5

Ouput (Screenshot6) :-

loops
Screenshot6
In this example condition will false and will not display “Hello” because condition counter is greater than 10.
Read More

Sunday, 16 February 2014

Concatenation in php

concatenation
"Con","cat","en","ation"
This is tutorial for concatenation within php. Now if you ever come across working with concatenation you will come to know about it in a better way.Before programming you may understand how to concatenate different variables together.Later on, How to printvariables which are concatenated in,Its very very simple in php.

Code for Concatenate in php (Screenshot1):-

Concatenation in php
Concatenation in php Screenshot1
 <?php

$day = 'Thursday';

$date = 31;

$year = 2011;



echo 'The date is '.$day.' '.$date.' ' .$year;

?>

Output (Screenshot2) :- 

Concatenation in php
Screenshot2
 In this code of  concatenate in php I am creating three variables i.e. $day, $date, $year.Now to echo one or more variables we have to join variables with dot which is called as concatenate. In single quotation (‘) inside echo statement we are echoing variables and text.Blank single quotation (‘) is used to leave space between variables.With Single quotation (‘) concatenate feature is most useful and with Double quotation (“) too its easy which I will so you in later tutorials.

Code For Concatenate in php (Screenshot3):-

Screenshot3

<?php

$day = 'Wednesday';

$date = 30;

$year = 2011;



echo 'The date is '.$day.' '.$date.' ' .$year;

?>

Output (Screenshot4) :-




In this examples i just updated variables and its automatically update output.So this is harder but fastest way to echo out variables by concatenate in string data.

Code for concatenate in php (Screenshot5):-
Concatenation in php
 Screenshot4


In this examples i just updated variables and its automatically update output.So this is harder but fastest way to echo out variables by concatenate in string data.

Code for concatenate in php (Screenshot5):-

 
concatenation in php
Screenshot5

<?php

$day = 'Wednesday';

$date = 30;

$year = 2012;



echo 'The date is <strong>'.$day.' '.$date.' ' .$year.'</strong>;

?>


Output (Screenshot6):-

concatenation in php
Screenshot6

In this example i am including html tags strong tag with concatenate strings, variables and also html tags.In this code it will bold variables.

Code for Concatenate in php with Double quotation marks(Screenshot7):-

Concatenation in php
Screenshot7

<?php

$day = 'Wednesday';

$date = 30;

$year = 2011;



echo "The date is $day $date $year";

?>



Output (Screenshot4) :-

Concatenation in php
Screenshot4

In this example we used Double quotation marks to concatenate string and variables and its easy because here you don’t write any dot (.) or to leave space in single quotation marks. Its very easy to Concatenate with double quotation marks.But single quotation marks are faster.Concatenate looks complex code in understanding there so i am recommending to always use single codes.

Code for Concatenate in php (Screenshot8):-

Concatenation in php
Screenshot8

<?php

$day = 'Wednesday';

$date = 30;

$year = 2011;



echo 'The date is $day $date $year';

?>

output (Screenshot9):-

Concatenation in php
Screenshot9
In this code if we use single quotation mark without concatenate with dot (.) it will echo variable name and does not reference to variable values.
Read More

About Me

Welcome to Extra Tutorials! My name is Mohammed and I am the 22 year writer, website developer, and photographer behind the blog. Thanks for visiting! Tutorials Jackpot… In addition to Developer, I love to develop websites and I love to write. Starting a php Blog was inevitable for me. What began as a simple way to share all of my Tutorials with friends and family has developed into my Part time job.

Mohammed Padela

WHAT IS PHP PROGRAMMING

WHAT IS PHP PROGRAMMING
WHAT IS PHP PROGRAMMING

Follow Us

Popular Posts

Designed ByBlogger Templates