Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Php practical programs, Study notes of Computer Science

lab Practical programs for bachelor of computer applications

Typology: Study notes

2018/2019

Uploaded on 07/10/2019

Ramya_28
Ramya_28 🇮🇳

4.5

(2)

2 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PHP PRACTICAL PROGRAMS
1. Develop and demonstrate an HTML file that includes PHP script to generate first ‘n’
Fibonacci numbers
<html>
<body>
<h1>Fibonacci seris</h1>
<form action="" method="post">
Enter the limit:
<input type="text" name="n"><br>
<input type="submit" name="submit"><br>
<?php
$a=0;
$b=1;
$c=0;
if(isset($_POST['submit']))
{
$x=$_POST['n'];
for($i=0;$i<$x;$i++)
{
$a=$b;
$b=$c;
echo "$c<br>";
$c=$a+$b;
}
}
?>
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Php practical programs and more Study notes Computer Science in PDF only on Docsity!

PHP PRACTICAL PROGRAMS

1. Develop and demonstrate an HTML file that includes PHP script to generate first ‘n’ Fibonacci numbers

Fibonacci seris

Enter the limit:

"; $c=$a+$b; } } ?>

2. Create a PHP script that accepts a number through inputbox and checks whether it is palindrome or not

Palindrom

Enter the number:

$len=strlen($string);

$num=0; for($i=0;$i<$len;$i++) { if(in_array($string[$i],$vowels)) { $num++; } } echo "Number of vowels: $num
"; $len=$len-1; echo "Number of characters: $len
"; $word=str_word_count($string); echo "Number of words: $word
"; $line=substr_count($_POST['str'],"\n"); echo "Number of lines: $line"; } ?>

4. Develop a simple calculator web application that takes 2 numbers and an operator (+,-,, /,%) from an HTML page and returns the result.*

simple calculator

Enter the number:



Enter another number:



Username:
session started at".date("h:i:sa",$tm)."
"; echo "
"; echo "

"; echo "
"; echo "Hello".$_SESSION['luser']; } ?> session_start();

date_default_timezone_set("Asia/Calcutta"); echo "

session started at".date("h:i:sa",time())."


"; echo "Thank you ".$_SESSION['luser']."
"; $session_time=time()-$_SESSION['start']; echo "Session duration ".$session_time." seconds"; ?>

6. Develop a web application that takes the name and age from an HTML page. If the age is less than 18, it should display a page with “hello , you are not authorized to visit this site” otherwise it should display the message, “, welcome to this site”.

Name:

Age:

else

{ $_SESSION['counter']=1; } echo "You have visited the page ".$_SESSION['counter']." time in this session"; ?>

8. Develop a database based web application that performs login validation and prints the corresponding message based on checking the username and password from MySQL database.

User Login

Username :

Password :

if($conn->connect_errno)

{ echo "Failed to connect with the server"; exit(); } else { $uname=$_POST['uname']; $pass=$_POST['pass']; $q="select Message from users where Username='$uname' and Password='$pass'"; $result=$conn->query($q); if($result->num_rows>0) { $row=$result->fetch_assoc(); echo "Message ".$row['Message']; } else { echo "Either username or password is wrong"; } } } ?>

else

{ echo "Cookie is not set. You have to set cookie"; } ?>

10. Create a PHP script that reads an array and displays the array in sorted order.

Sorting an array

Enter the string:
if($array[$i]>$array[$j]) { $temp=$array[$i]; $array[$i]=$array[$j]; $array[$j]=$temp; } } } print_r($array); } ?>

11. Develop a web application that develops a student registration form and displays the entered details to another page

Student Registration Form
Name
Student Details
Name
Age
Gender
Date of Birth
course
Phone no

12. Create a MySQL table containing a few details of employees. Create a PHP web application that can save the employee data given through HTML forms and can fetch and display the table contents into an HTML table.

$q="insert into empdet(dept,name,id,sal)values

('$edept','$ename','$eid','$esal')"; if($conn->query($q)===TRUE) { echo ""; } else die('error'); } ?>

Employee details
Employee department
Employee Name
connect_errno)

echo "Failed to connect with the server"; exit(); } $query="select * from empdet"; if($result=$conn->query($query)) { while($row=$result->fetch_assoc()) { echo "

"; echo ""; echo ""; echo ""; echo ""; echo ""; } } $conn->close(); ?>

Employee Details
Employee Department Employee Name Employee id Employee salary
".$row['dept']."".$row['name']."".$row['id']."".$row['sal']."

13. Create a database application in PHP that can delete a student record on accepting the enrolment number of the student. A message should be displayed on deletion of the record and the contents of the table should be displayed