Calculate add,sub,mul using php

Friday, July 30th, 2010 Basic PHP

Steps:

1. Create new html file and copy calculate.html code and save it as calculate.html.

2. Create new php file and copy calculation.php code and save it as calculation.php.

3. Run calculate.html, then it will display the html data.

4. Enter value1, value2 and press add or sub or mul button and press calculate button.

5. Then it will transfer to calculation.php which displays the output.

calculate.htm:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>calculation</title>
</head>

<body>
<form method=”post” action=”calculation.php”>
Value 1: <input type=”text” name=”val1″ size=”7″><br /><br />
Value 2: <input type=”text” name=”val2″ size=”7″>
<p>
<input type=”radio” name=”calculate” value=”add”  />
add
<input type=”radio” name=”calculate” value=”sub”  />
sub
<input type=”radio” name=”calculate”  value=”mul”/>
mul
</p>
<input type=”submit” name=”submit” value=”calculate”/>
</form>
</body>
</html>

It displays the output as:

Value 1:

Value 2:
add

sub

mul

calculation.php:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Untitled Document</title>
</head>

<body>
<?php
if(($_POST['val1']==”") || ($_POST['val2']==”"))
{
header(“location: calculate.html”);
exit();
}
if($_POST['calculate']==”add”)
{
$result=$_POST['val1']+$_POST['val2'];
}
else if($_POST['calculate']==”sub”)
{
$result=$_POST['val1']-$_POST['val2'];
}
else if($_POST['calculate']==”mul”)
{
$result=$_POST['val1']*$_POST['val2'];
}
echo “Calculation is: $result”;
?>
</body>
</html>

An example output for add by giving the input as value1 as 5 and value2 as 5 is:
Calculation is: 10

TAGS:

Transfer data from one page to another using php

Wednesday, July 28th, 2010 Basic PHP, PHP Scripts

Steps:

1:Create new php file and copy file1 code and save it as file1.php.

2.Create another new php file and copy file2 code and save it as file2.php.

3.Run file1.php, then it will display the file1 data.

4.Enter your name, age and location and press the submit button.

5.It will transfer to file2.php and displays the output.

file1:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>table1</title>
<script language=”javascript” type=”text/javascript”>
function check()
{
if(document.getElementById(‘name1′).value==”)
{
alert(“Please enter your name”);
document.getElementById(‘name1′).focus();
}
else if(document.getElementById(‘age1′).value==”)
{
alert(“please enter your age”);
document.getElementById(‘age1′).focus();
}
else if(document.getElementById(‘location1′).value==”)
{
alert(“please enter the location”);
document.getElementById(‘location1′).focus();
}
else
{
document.form.submit();
}
}
</script>
</head>

<body>
<form method=”post” action=”file2.php” name=”form” >
<table width=”100%” border=”0″>
<tr>
<td><label>Enter your name: </label>
</td>
<td><input type=”text” name=”name”  id=”name1″; />
</td>
</tr>
<tr>
<td><label>Enter your age:</label>
</td>
<td><input type=”text” name=”age” id=”age1″; />
</td>
</tr>
<tr>
<td><label>Enter the location:</label>
</td>
<td><input type=”text” name=”location” id=”location1″; />
</td>
</tr>
<tr>
<td colspan=”2″> <div align=”center”>
<input type=”button” value=”Submit” onclick=”check();” name=”Submit” />

</div></td>
</tr>
</table>
</form>
</body>
</html>

//save this as file1.php

It will display the output as:

file2:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>table2</title>
</head>

<body>
<?php
$var1=$_POST['name'];
$var2=$_POST['age'];
$var3=$_POST['location'];
echo “your name is: $var1″.”<br/>”;
echo “your age is: $var2″.”<br/>”;
echo “loaction is: $var3″;
?>
</body>
</html>

//save this as file2.php

after entering your name, age and location and pressing the submit button, it displays the output.

For example:

your name is: John
your age is: 25
loaction is: CA

TAGS: , ,

Change Your Page Background Color Dynamically using Java Script

Tuesday, July 27th, 2010 Style Sheet Designs

Following code is used to change a page color from your select option in select box.

Copy and Paste following code in your site page.

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>Change Your page Background Color Using Java Script</title>
<link href=”blue.css” type=”text/css” title=”pagestyle”  rel=”stylesheet” id=”pagestyle”/>
<script type=”text/javascript”>
function setCookie(c_name,value,expiredays)
{
var changecolor=new Date();
changecolor.setDate(changecolor.getDate()+expiredays);
document.cookie=c_name+ “=” +escape(value)+
((expiredays==null) ? “” : “;expires=”+changecolor.toUTCString());
}

// Get  value  stored in Cookie
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + “=”);
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(“;”,c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return “”;
}

//  This function run on body load event
function  loadTheme()
{
var c_val=getCookie(“colorscheme”);
if (c_val!=”")
document.getElementById(“pagestyle”).href=c_val+’.css’;

}
// This function call  ensures  to load  the Previously selected color Scheme by User
loadTheme();

//  This function call on change of select box options
function  changeTheme()
{
var c_val=document.getElementById(“changescheme”).value;
document.getElementById(“pagestyle”).href=c_val+’.css’;
setCookie(“colorscheme”,c_val,30);

}
</script>

</head>
<body>
<h1>Please Select Your Page Background Color..</h1>
<select name=”changescheme” id=”changescheme” onchange=”changeTheme()”>
<option value=”white”>White</option>
<option value=”red”>Red</option>
<option value=”blue”>Blue</option>
<option value=”orange”>Orange</option>
<option value=”black”>Black</option>
</select>
</body>
</html>

Using Style sheet Files are

blue.css
root {
display: block;
}

body
{
background-color:#003366;
}

h1{font-family:helvitica;font-size:20px;color:#ffffff;}

white.css
root {
display: block;
}

body
{ background-color:#FFFFFF;

}

h1{font-family:helvitica;font-size:20px;color:#ffffff;}

TAGS: , ,

Giving Links In CSS

Tuesday, July 27th, 2010 Style Sheet Designs

/* The Example1 will be having the font styles,colors and  font size for the content present in Example2. copy and paste the code of Example2 to get the output.*/

Example1.css

body
{
background-color:yellow;
}
h1
{
font-size:36pt;
}
h2
{
color:blue;
}
p
{
margin-left:50px;
}

Example2.css

<html>
<head>
<link rel=”stylesheet” type=”text/css”  href=”example1.css”  />
</head>
<body>
<h1>Hai!!</h1>
<h2>Have A Nice Day</h2>
</body>
</html>

Output:

Hai!!

Have A Nice Day

TAGS:

JavaScript To Find Greatest Among 3 Numbers

Friday, July 23rd, 2010 javascript

/* The Following Script will display the greatest among three numbers*/

<html>
<head>
<h1>Greatest Among Three Numbers</h1>
</head>
<body>
<script type=”text/javascript”>
var a=10,b=20,c=7;

/* checks a>b and a>c  if  both conditions satisfied, A is greater */

if (a>b  && a>c)
{
document.write(“<b>A is greater</b>”);
}

/* checks b>a  and b>c  if  both conditions satisfied, b is greater */

if (b>a  && b>c)
{
document.write(“<b>B is greater</b>”);
}

/* if the above two conditions were false c is greater*/

else
{
document.write(“<b>C is greater</b>”);
}
</script>
</body>
</html>

The Output will be:

Greatest Among  Three Numbers

B is Greater


javascript-displays the alert message

Friday, July 23rd, 2010 javascript, Programming

Create new html file and copy the code and save it as popup.html.

popup.html

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Untitled Document</title>
<script type=”text/javascript”>
function popup()
{
alert(“Good morning”);
}
</script>
</head>

<body>
<input type=”button” onClick=”popup()” value=”clickhere” />
</body>
</html>

It displays the output clickhere button which displays the alert message as “Good morning”

TAGS:

A Simple javascript

Friday, July 23rd, 2010 Programming

<script type=”text/javascript”>
<!–
document.write(“WELCOME”);
–>
</script>

It display the output as:

WELCOME

TAGS:

To display the current day and image for a particular day

Friday, July 23rd, 2010 Programming

<?php
$today=date(l);
if($today==Monday)
{
echo “Today is Monday” .”<br/>”;
echo “<img src=’images/image1.gif’>”;
}
elseif($today==Tuesday)
{
echo “Today is Tussday” .”<br/>”;
echo “<img src=’images/image2.gif’>”;
}
elseif($today==Wedsday)
{
echo “Today is Wedsday” .”<br/>”;
echo “<img src=’images/image3.gif’>”;
}
elseif($today==Thursday)
{
echo “Today is Thursday” .”<br/>”;
echo “<img src=’images/image4.gif’>”;
}

elseif($today==Friday){
echo “Today is Friday”.”<br/>”;
echo “<img src=’images/image5.gif’>”;
}

elseif($today==Saturday){
echo “Today is Saturday”.”<br/>”;
echo “<img src=’images/image6.gif’>”;
}

elseif($today==Sunday){
echo “Today is Sunday”.”<br/>”;
echo “<img src=’images/image7.gif’>”;
}
?>

//create the folder name as images and store the 7 images. So, it will display the todays image.

It display the output as:

Today is Friday

TAGS:

To display current date,no.of days and weeks in a month and year using php

Friday, July 23rd, 2010 Basic PHP, Programming

1:Create new php file and copy the code and save it as file1.php.

2.Run file1.php, then it will display the current date and no.of days,weeks in a month and year.

<?php
echo  “My name is: John”.”<br/>”;
echo “current date is:”.”\n” .date(“Y m d h: s: m”) .”<br/>”;
echo “No of days in a month:”.”\n” .cal_days_in_month( CAL_GREGORIAN, 07, 2010) .”<br/>”;
echo “No of weeks in a month:”.”\n”.date(“w”, mktime(0,0,0,12,31,2010)) .”<br/>”;
echo “No of weeks in a year:”.”\n” .date(“W”, mktime(0,0,0,12,31,2010)) .”<br/>”;
?>

It display the output as:

My name is: John
current date is: 2010 07 23 04: 46: 07
No of days in a month: 31
No of weeks in a month: 5
No of weeks in a year: 52

TAGS:

Javascript to wish “Good Morning”

Thursday, July 22nd, 2010 javascript

WISHES FOR A DAY

/* This script will display A “Good Morning” Message if the time is less than or equal to 10.Otherwise, it display a “Message Good Day”*/

<html>
<body>
<script type=”text/javascript”>
var d = new Date();
var time = d.getHours();
if (time <= 10)
{
document.write(“<h1>Hai Good morning!!!</h1>”);
}
else
{
document.write(“</h1>Good day!!!!!!!</h1>”);
}
</script>
</body>
</html>

It produces the output as :

if the time is <=10

Hai!!!!Good morning

otherwise

Good day!!!!!!!