Professional Documents
Culture Documents
no: 1
Date: 14/6/2016
NATURAL NUMBERS
AIM:
To create a program to display first 10 natural numbers
ALGORITHM:
Step 1: Start the process
Step2: Open notepad-> file->new
Step 3: Open the html tag, body tag and php tag
Step 4: Using for loop display first 10 natural numbers.
Step 5: Save the program in working folder with the extension .php
Step 6: Run the program in the browser window through local host.
Step 7: Display the result
Step 8: Stop the process
NATURAL NUMBERS
To display first 10 natural numbers
<html>
<body>
<?php
echo "The first 10 natural numbers are"."<br/>";
for($i=1;$i<=10;$i++)
{
echo $i."<br/>";
}
?>
</body>
</html>
Output:
RESULT:
Hence the above program has been executed and verified successfully.
Ex.no: 2
3
Date: 23/6/2016
AIM:
To display the current date and time using php.
ALGORITHM:
Step 1: Start the process.
Step 2: Open the notepad.
Step 3: Set the default time zone Asia/Calcutta assigned with date.
Step 4:Using date function display the D,d M Y h:i:s, d.m.y, d-m-Y, H:i:s a,
h:i:sA, F j,Y,g:i,A.
Step 5: Finally using date function display the (total no of days) I\t\\i\s \t\h\e
js \d\a\y.
Step 6: Save the in working folder with the extension .php
Step 7: Display the result.
Step 8: Stop the process.
Output:
RESULT:
Hence the above program has been executed and verified successfully.
Ex.no: 3
Date :6/7/2016
BACKGROUND COLOR
AIM:
To change the background color of the days in a week.
ALGORITHM:
Step 1: Start the process.
Step 2: Open the notepad. Save the program with .php extension.
Step 3: Include the php tags.Set the default time zone(Asia/Calcutta) and
assign today as date
with week.
Step 4: Using switch case assign colors to all those 6 cases,which
corresponds to each day in a week.
Step 5: In the echo give bodybgcolor and date also assigned there.Close the
tags.
Step 6: Display the result.
Step 7: Stop the process.
BACKGROUND COLOR
8
<html>
<body>
<?php
$w=date_default_timezone_set('Asia/calcutta');
$today=date('w');
switch($today)
{
case 0:
$bgcolor="#ffffff";
break;
case 1:
$bgcolor="#ffff00";
break;
case 2:
$bgcolor="#ff00ff";
break;
case 3:
$bgcolor="#00ffff";
break;
case 4:
$bgcolor="#ff0000";
break;
case 5:
$bgcolor="#00ff00";
break;
default:
$bgcolor="#000000";
break;
}
echo "<body bgcolor=\"$bgcolor\">";
echo date('l');
?>
</body>
</html>
Output:
10
RESULT:
Hence the above program has been executed and verified successfully.
Ex.no: 4
11
Date: 20/7/2016
AIM:
To create a program to connect student information with SQL.
ALGORITHM:
Step 1: Start the process.
Step 2: Open the notepad. Save the program with .php extension.
Step 3: Include the php tags, open a connection and define the username
and password.
Step 4: If the connection is established create a database and display a
message as database created.
Step 5: If the connection is not established display the error message.
Step 6: Select the database and create a student table using sql query.
Step 7: Insert the values with required fields of student table using INSERT
query.
Step 8: Fetch the details using SELECT query.
Step 9: Display the result.
Step 10: Close the connection.
Step 11: Stop the process.
12
STUDENT INFORMATION
<html>
<body>
<?php
$con=mysql_connect("localhost","root","admin");
if(!$con)
{
die('could not connect=' .mysql_error());
}
mysql_select_db("student",$con);
$sql="CREATE TABLE stu(f1 varchar(15),l1 varchar(15),a1 int (3))";
mysql_query($sql,$con);
mysql_select_db("student",$con);
mysql_query("INSERT INTO stu(f1,l1,a1) VALUES('Rekha','A','18')");
13
14
Output:
RESULT:
Hence the above program has been executed and verified successfully.
15
Ex.no : 5
Date : 9/8/2016
AIM:
To create a program to connect employee information with SQL.
ALGORITHM:
Step 1: Start the process.
Step 2: Open the notepad. Save the program with .php extension.
Step 3: Include the php tags, open a connection and define the username
and password.
Step 4: If the connection is established create a database and display a
message as database
created.
Step 5: If the connection is not established display the error message.
Step 6: Select the database and create an employee table using sql query.
Step 7: Insert the values with required fields of employee table using INSERT
query.
Step 8: Fetch the details using SELECT query.
Step 9: Display the result.
Step 10: Close the connection.
Step 11: Stop the process.
16
EMPLOYEE DETAILS
<html>
<body>
<?php
$con=mysql_connect("localhost","root","admin");
if(!$con)
{
die('could not connect=' .mysql_error());
}
mysql_select_db("emp1",$con);
$sql="CREATE TABLE employee(f1 varchar(15),l1 varchar(15),a1 int (3))";
mysql_query($sql,$con);
mysql_select_db("emp1",$con);
mysql_query("INSERT INTO employee(f1,l1,a1) VALUES('Anu','R','22')");
mysql_query("INSERT INTO employee(f1,l1,a1) VALUES('Ashi','B','23')");
17
18
Output:
RESULT:
Hence the above program has been executed and verified successfully.
19
Ex.no : 6
Date : 24/8/2016
WORD COUNT
AIM:
To program to create a counting the word.
ALGORITHM:
Step 1: Start the program.
Step 2: Open the notepad.Save the program with .php extension.
Step 3: Include PHP tags.
Step 4: In php FORM get the input string and search string from the user.
Step 5:Count the number of times the search string is there in the input
string using string functions.
Step 6: Display the count.
Step 7: Stop the process.
20
WORD COUNT
<html>
<body>
<?php
if(!isset($_POST['submit']))
{
?>
<form method="POST" action="string11.php">
Enter the string<br/>
<input type="text" name="str" size="50"/>
<br/>
Enter the word to search<br/>
<input type="text" name="word" size="50"/>
<p>
<input type="submit" name="submit" value="submit"/>
</form>
<?php
}
else
{
$x=$_POST['str'];
$y=$_POST['word'];
echo "Your Sentence is:$x";
echo "<br/>";
echo "Word to search is:$y";
echo "<br/>";
21
Output:
22
RESULT:
Hence the above program has been executed and verified successfully.
Ex.no : 7
23
Date : 31/8/2016
HIT COUNT
AIM:To display the count of person who visited the current page.
ALGORITHM:Step 1: Start the process.
Step 2: Open notepad->File->new.
Step 3: open the html tag, body tag and php tag.
Step 4: create a temporary file with .dat extension.
Step 5: check if file is created or not using. If file is not created then open
file with write mode. Display error if unable to create.
Step 6: Open the file with read mode. Read the file and increment the
counter variable.
Step 7: Display the counter value using echo statement and close the files.
Step 8: Save and run the program.
Step 9: Stop the process.
.
HIT COUNT
<html>
24
<head>
<title>HIT COUNTER</title>
</head>
<body>
<h1>A hit counter</h1>
<?php
$counterFile="./count.dat";
if(!file_exists($counterFile))
{
if(!($handle=fopen($counterFile,"w")))
{
die("cannot create the counter file");
}
else
{
Fwrite($handle,0);
Fclose($handle);
}
}
if(!($handle=Fopen($counterFile,"r")))
{
die("cannot read the counter file");
}
$counter=(int)Fread($handle,20);
Fclose($handle);
$counter++;
25
Output:
26
RESULT:
Hence the above program has been executed and verified successfully.
27