0% found this document useful (0 votes)
11 views25 pages

Tybsc Sem2 PHP Pract - Final - Set

The document outlines assignments for a T.Y.B.Sc. course on Internet Programming using PHP at L.K. Dr. P.R. Ghogrey Science College. It includes tasks such as designing web pages with HTML, writing PHP scripts for various programming concepts, and demonstrating OOP principles. Each assignment is detailed with specific requirements and example code snippets.

Uploaded by

laita nikam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views25 pages

Tybsc Sem2 PHP Pract - Final - Set

The document outlines assignments for a T.Y.B.Sc. course on Internet Programming using PHP at L.K. Dr. P.R. Ghogrey Science College. It includes tasks such as designing web pages with HTML, writing PHP scripts for various programming concepts, and demonstrating OOP principles. Each assignment is detailed with specific requirements and example code snippets.

Uploaded by

laita nikam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

S.S.V.P.

Sanstha’s
L.K.Dr.P.R.Ghogrey Science College,Dhule
Department of Computer Science
INDEX
Class : T.Y.B.Sc. Subject: UG-CS-LAB-305 Year: 2017-18
Sem-II Roll no : ____

Internet Programming using PHP

Sr. Name of Assignment Date Signature


No.
1 Design web pages using HTML that will contain
online admission forms.
2 Write PHP scripts that demonstrate fundamentals PHP.
3 Write PHP script that will display grade based on
criteria given below using the marks obtained in
T.Y.Bsc. Examination.
a. Distinction (70 and above)
b. First Class (60 - 69)
c. Pass (40 - 59)
d. Fail (below 40)
4 Write a PHP script to demonstrate different String
functions.
5 Write a PHP script to demonstrate array.
6 Write a PHP script to use Functions (Call by Value,
Call by reference).
7 Write a PHP script to Demonstrate OOPS Concept in
PHP.
8 Write a PHP script to demonstrate Exception Handling.
9 Write a PHP script to demonstrate Form Data Handling
using Get and Post methods.
10 Design a database in MYSQL using PHP. Create table
in database. Store, Update, Delete and Retrieve data
from the table. Display the data from the table.
11 Write a PHP script to store, retrieve and delete cookies
on your local machine.
12 Write a PHP script to store, retrieve and delete data
using session variables.
S. S. V. P. Sanstha’s
L. K. Dr. P. R. Ghogrey Science College, Dhule
Department of Computer Science
Lab on Internet Programming using PHP

Roll No. :- ____ Date: ___/___/2018


Name :- _________________________________________________

Assignment No-1) Design web pages using HTML that will contain online
admission forms.

<html>
<head>
<title> Admission Form</title>
</head>

<body bgcolor=orange text=blue>


<form >
<center> <h3>S. S. V. P. Santhas <br>
L. K. Dr. P. R. Ghogrey Science Collage, Dhule</h3>
<h2>Admission from</h2> </center>

&nbsp;&nbsp;Frist Name : <input type="text" name="fname" size=20


maxlength=15/>
&nbsp;&nbsp;Middle Name : <input type="text" name="mname" size=20
maxlength=15/>
&nbsp;&nbsp;Last Name : <input type="text" name="lname" size=20
maxlength=15/>
<br><br>

&nbsp;&nbsp;Date of brith : <input type="text" name="dob" size=20


maxlength=15/>
<br> <br>

&nbsp;&nbsp;Gender :
<input type="radio" name="gender" value="Male" checked="checked">Male
<input type="radio" name="gender" value="Female">Female
<br><br>
&nbsp;&nbsp;Caste :
<input type="radio" name="caste" value="OBC" checked="checked">OBC
<input type="radio" name="caste" value="SC">SC
<input type="radio" name="caste" value="NT">NT
<input type="radio" name="caste" value="OPEN">OPEN
<br><br>

&nbsp;&nbsp;Subjects :
<input type="checkbox" name="subject" value="Computer"
checked="checked">Computer
<input type="checkbox" name="subject" value="Mathematics">Mathematics
<input type="checkbox" name="subject" value="Physics">Physics
<input type="checkbox" name="subject" value="Electronics">Electronics
<input type="checkbox" name="subject" value="Chemistry">Chemistry
<br><br>

&nbsp;&nbsp;Year :
<select name="year">
<option>F.Y.B.Sc.</option>
<option>S.Y.B.Sc.</option>
<option>T.Y.BSc.</option>
<option>M.Sc.I</option>
<option>M.Sc.II</option>
</select>
<br><br>

&nbsp;&nbsp;City : <br>
<select name="city" size="4">
<option selected="selected">Dhule</option>
<option>Jalgaon</option>
<option>Pune</option>
<option>Jalna</option>
<option>Aurangabad</option>
<option>Nashik</option>
</select>
<br><br>
<input type="reset" name="reset" value="Reset">
<input type="submit" name="submit" value="Submit">
</form>
</body>

</html>

Output :
S. S. V. P. Sanstha’s
L. K. Dr. P. R. Ghogrey Science College, Dhule
Department of Computer Science
Lab on Internet Programming using PHP

Roll No. :- ____ Date: ___/___/2018


Name :- _________________________________________________

Assignment No-2) Write PHP scripts that demonstrate fundamentals PHP.

<?php
$num = 1;
Switch($num)
{
Case 1:
$no = 5;
$fact = 1;
$i = 1;
while($i <= $no)
{
$fact = $fact*$i;
$i++;
}
echo $fact;
break;
case 2:
$no = 7;
$a = 0;
$b = 1;
for($i = 0; $i <$no; $i++)
{
$c = $a + $b;
echo "<br>$c";
$a = $b;
$b = $c;
}
Case 3:
$no = 46;
if($no%2 == 0)
echo "even";
else
echo "odd";
}
Case 4:
$no = 2;
switch($no)
{
case 1 : echo "first prize";
break;
case 2 : echo "second prize";
break;
case 3 : echo "thirld prize";
break;
default: echo "participent prize";
break;
}
}
?>
</html>

Output :
120
S. S. V. P. Sanstha’s
L. K. Dr. P. R. Ghogrey Science College, Dhule
Department of Computer Science
Lab on Internet Programming using PHP

Roll No. :- ____ Date: ___/___/2018


Name :- _________________________________________________

Assignment No-3) Write PHP script that will display grade based on
criteria given below using the marks obtained in T.Y.Bsc. Examination.

<?php
$a = 89;
if($a >= 70 && $a <= 100)
echo "Distinction";
else if($a >= 60 && $a <= 69)
echo "First Class";
else if($a >= 40 && $a <= 59)
echo "Pass";
else if($a >= 0 && $a < 40)
echo "Fail";
else
echo "Unformatted Input";
?>
</html>

Output :

Distinction
S. S. V. P. Sanstha’s
L. K. Dr. P. R. Ghogrey Science College, Dhule
Department of Computer Science
Lab on Internet Programming using PHP

Roll No. :- ____ Date: ___/___/2018


Name :- _________________________________________________

Assignment No-4) Write a PHP script to demonstrate different String


functions.

<html>
<head>
<title>PHP Script For String demo</title>
</head>

<body>
<?php

$str1 = "my php program for string demonstration";


$str2 = 10;
$str3 = "10";

if($str2 == $str3)
echo "<br>both string are equal";
else
echo "<br>both string are not equal";
if($str2 === $str3)
echo "<br>both string are equal in type";
else
echo "<br>both string are not equal in type";

echo "<br>" . strlen($str1);


echo "<br>" . trim(" php ");
echo "<br>" . ltrim(" php ");
echo "<br>" . rtrim(" php ");
echo "<br>" . strtoupper($str1);
echo "<br>" . strtolower($str1);
echo "<br>" . strcmp("php", "php");
echo "<br>" . strcmp("php", "sql");
echo "<br>" . strcmp("c", "java");
echo "<br>" . strcmp("python", "dbms");

echo "<br>" . substr($str1, 3, 11);;


echo "<br>" . substr($str1, 7);;
echo "<br>" . substr_count($str1, "ra");
echo "<br>" . substr_replace($str1, "java ", 3, 4);;
print "<br>" . strrev("java");
print "<br>" . str_repeat("php ", 10);
print "<br>" . str_pad("dbms", 10, "*");
print "<br>" . str_pad("dbms", 10, "*", STR_PAD_LEFT);
print "<br>" . str_pad("dbms", 10, "*", STR_PAD_BOTH);

$strexp = "java,php,sql,c,perl";
$exp = explode("," , $strexp);
print "<br>";
foreach($exp as $val)
echo "\t" . $val;
$imp = implode('+', $exp);
echo "<br>" . $imp;

?>
</body>
</html>
Output :

both string are equal


both string are not equal in type
39
php
php
php
MY PHP PROGRAM FOR STRING DEMONSTRATION
my php program for string demonstration
0
-1
-1
1
php program
program for string demonstration
2
my java program for string demonstration
avaj
php php php php php php php php php php
dbms******
******dbms
***dbms***
java php sql c perl
java+php+sql+c+perl
S. S. V. P. Sanstha’s
L. K. Dr. P. R. Ghogrey Science College, Dhule
Department of Computer Science
Lab on Internet Programming using PHP

Roll No. :- ____ Date: ___/___/2018


Name :- _________________________________________________

Assignment No-5) Write a PHP script to demonstrate array.

<html>
<body>
<?php
echo "<br>indexed array : ";
$indexarr = array(10, 20, 30, 40, 50);
$indexarr[5] = 60;
$indexarr[6] = 70;
foreach($indexarr as $ele)
echo " $ele ";

echo "<br>name array : ";


$namearr = array('c', 'c++', 'java', 'php', 'sql', 'vb.net', 'dbms');
foreach($namearr as $ele)
echo " $ele ";

echo "<br>assosiative array : ";


$assoarr = array("mouse" => 200, 'keyboard' => 400, 'display' => 7000);
$assoarr["cpu"] = 6000;
$assoarr['printer'] = 8000;
foreach($assoarr as $ele)
echo " $ele ";
echo "<br>$assoarr[keyboard] ";

echo "<br>multidimentional array : ";


$multiarr = array(array('no', 'name', 'class'),
array(21, 'charles', 'tybsc'),
array(31, 'alex', 'tybsc')
);
foreach($multiarr as $outer)
{
echo "<br>";
foreach($outer as $inner)
echo " $inner ";
}
echo "<br>";

//array sorting functions-


echo "<br>asc sort of indexed array : ";
sort($namearr);
foreach($namearr as $ele)
echo "$ele ";

echo "<br>desc sort of indexed array : ";


rsort($namearr);
foreach($namearr as $ele)
echo "$ele ";

echo "<br>asc sort of assosiated array with value : ";


asort($assoarr);
foreach($assoarr as $ele)
echo "$ele ";

echo "<br>desc sort of assosiated array with value : ";


arsort($assoarr);
foreach($assoarr as $ele)
echo "$ele ";

echo "<br>asc sort of assosiated array with key : ";


ksort($assoarr);
foreach($assoarr as $ele)
echo "$ele ";

echo "<br>desc sort of assosiated array with key : ";


krsort($assoarr);
foreach($assoarr as $ele)
echo "$ele ";

?>
</body>
</html>

Output :

indexed array : 10 20 30 40 50 60 70
name array : c c++ java php sql vb.net dbms
assosiative array : 200 400 7000 6000 8000
400
multidimentional array :
no name class
21 charles tybsc
31 alex tybsc

search 'php'in the name array : 3


search 'dbms'in the name array : 6
shuffle the name array : c c++ sql dbms java php vb.net

asc sort of indexed array : c c++ dbms java php sql vb.net
desc sort of indexed array : vb.net sql php java dbms c++ c
asc sort of assosiated array with value : 200 400 6000 7000 8000
desc sort of assosiated array with value : 8000 7000 6000 400 200
asc sort of assosiated array with key : 6000 7000 400 200 8000
desc sort of assosiated array with key : 8000 200 400 7000 6000
S. S. V. P. Sanstha’s
L. K. Dr. P. R. Ghogrey Science College, Dhule
Department of Computer Science
Lab on Internet Programming using PHP

Roll No. :- ____ Date: ___/___/2018


Name :- _________________________________________________

Assignment No-6) Write a PHP script to use Functions (Call by Value, Call
by reference).

<html>
<head>
<title>PHP Script For Functions</title>
</head>
<body>
<?php

function display()
{
echo "function without parameter";
}
function sum($a, $b = 4, $c = 2)
{
echo "<br>function using parameter with call by value:";
$d = $a + $b + $c;
return $d;
}
function double(&$a, &$b)
{
echo "<br>function using parameter with call by reference:";
$a = $a * 2;
$b = $b * 2;
}

function varpara ($a1, $a2, $a3, $a4, $a5)


{
echo "<br>demo of variable parameters:";
for($i = 0; $i < func_num_args(); $i++)
{
echo "<br>" . func_get_arg($i);
}
}

display();
$a1 = 5;
$b1 = 7;
$c1 = 3;
$d1 = sum($a1, $b1, $c1);
echo "<br>sum = $d1";
$d1 = sum($a1);
echo "<br>sum = $d1";
double($a1, $b1);
echo "<br>a1 = $a1 <br>b1 = $b1";
varpara(11, 12, 13, 14, 15);

?>
</body>
</html>

Output :

function without parameter


function using parameter with call by value:
sum = 15
function using parameter with call by value:
sum = 11
function using parameter with call by reference:
a1 = 10
b1 = 14
demo of variable parameters:
11
12
13
14
15
S. S. V. P. Sanstha’s
L. K. Dr. P. R. Ghogrey Science College, Dhule
Department of Computer Science
Lab on Internet Programming using PHP

Roll No. :- ____ Date: ___/___/2018


Name :- _________________________________________________

Assignment No-7) Write a PHP script to Demonstrate OOPS Concept in


PHP.

<html>
<head>
<title>PHP Script For OOPs Concepts</title>
</head>
<body>
<?php
interface interfc {
public function interfun();
}

abstract class abstcls {


public function abstfun() {
echo "<br>abstract class function";
}
}

class derivedinter implements interfc {


public function interfun() {
echo "<br>interface function definition here";
}
}

class derivedabst extends abstcls{


public function derivedfun() {
echo "<br>derived class function";
}
}
final class finlcls {
private $c;
public function __construct() {
echo "<br>final class constructor";
}
public function add($a, $b) {
$this->c = $a + $b;
echo "<br>adition = $this->c";
}
function __destruct() {
echo "<br>final class destructor";
}
}

$obj1 = new derivedinter;


$obj1->interfun();

$obj2 = new derivedabst;


$obj2->derivedfun();
$obj2->abstfun();

$obj3 = new finlcls;


$obj3->add(5, 7);

?>
</body>
</html>

Output :
interface function definition here
derived class function
abstract class function
final class constructor
addition = 12
final class destructor
S. S. V. P. Sanstha’s
L. K. Dr. P. R. Ghogrey Science College, Dhule
Department of Computer Science
Lab on Internet Programming using PHP

Roll No. :- ____ Date: ___/___/2018


Name :- _________________________________________________

Assignment No-8) Write a PHP script to demonstrate Exception Handling.

<html>
<head>
<title>PHP Script For Exception Handling</title>
</head>
<?php
function division($a, $b) {
if($b == 0) {
throw new exception('divide by zero');
}
Else {
$ans = $a / $b;
echo "<br>ans = $ans";
}
}
Try {
division(10, 3);
division(20, 4);
division(5, 0);
}catch(exception $e) {
echo "<br>" . $e->getMessage();
}
?>
</html>

Output :
ans = 3.3333333333333
ans = 5
divide by zero
S. S. V. P. Sanstha’s
L. K. Dr. P. R. Ghogrey Science College, Dhule
Department of Computer Science
Lab on Internet Programming using PHP

Roll No. :- ____ Date: ___/___/2018


Name :- _________________________________________________

Assignment No-9) Write a PHP script to demonstrate Form Data Handling


using Get and Post methods.

File 1 -
<html>
<head><title>TYBSc Addmision</title></head>

<form name="form1" method="POST" action="destination.php">


<table border=2>

<tr>
<td colspan=4>Application for TYBSc </td>
</tr>

<tr>
<td>Enter rollno</td>
<td colspan=4><input type="text" name="txtrno"/></td>
</tr>

<tr>
<td>Enter first name</td>
<td colspan=4><input type="text" name="txtfname"/></td>
</tr>

<tr>
<td>Enter last name</td>
<td colspan=4><input type="text" name="txtlname"/></td>
</tr>
<tr>
<td>Branch</td>
<td><input type="Radio" name="rbtn" value="Comp"/
checked="checked">comp</td>
<td><input type="Radio" name="rbtn" value="Math"/>micro</td>
<td><input type="Radio" name="rbtn" value="Elex"/>zoo</td>
</tr>

<tr>
<td>Sem</td>
<td colspan=4><select name="semcombo">
<option value="sem1" selected="selected">sem1</option>
<option value="sem2">sem2</option>
</select>
</tr>

<tr>
<td colspan=2><input type="submit" name="btndis" value="display"/></td>
</tr>

</table>
</form>
</body>
</html>

File 2 - Save below file with name "destination.php"


<?php
if(isset($_POST['btndis']))
{
echo "Application for TYBSc:-";
echo "<br>rollno = " . $_POST['txtrno'];
echo "<br>fname = " . $_POST['txtfname'];
echo "<br>lname = " . $_POST['txtlname'];
echo "<br>branch = " . $_POST['rbtn'];
echo "<br>sem = " . $_POST['semcombo'];
}
?>
Output :

When clicked on the display button-

Application for TYBSc:-


rollno = 14
fname = Ashok
lname = Kumawat
branch = Comp
sem = sem2

S. S. V. P. Sanstha’s
L. K. Dr. P. R. Ghogrey Science College, Dhule
Department of Computer Science
Lab on Internet Programming using PHP

Roll No. :- ____ Date: ___/___/2018


Name :- _________________________________________________

Assignment No-10) Design a database in MYSQL using PHP. Create table


in database. Store, Update, Delete and Retrieve data from the table.
Display the data from the table.

<html>
<?php
$conn = mysqli_connect("localhost", "root", "");
if(!$conn) {
echo "connection failed";
echo mysql_error();
}
else {
echo "connected to mysql successfully...";
}
mysqli_query($conn, "CREATE DATABASE ASK_DB");
mysqli_select_db($conn, "ASK_DB");

$sql = "CREATE TABLE ASK_TABLE(


ROLLNO INT, NAME CHAR(30), AGE INT)";
mysqli_query($conn, $sql);

mysqli_query($conn, "INSERT INTO ASK_TABLE


VALUES(1, 'ASHOK', 20)" );
mysqli_query($conn, "INSERT INTO ASK_TABLE
VALUES(2, 'CHARLES', 34)" );
mysqli_query($conn, "INSERT INTO ASK_TABLE
VALUES(3, 'PETER', 25)" );

echo"<br> <br>Table Created:";


$sql = mysqli_query($conn, "SELECT *FROM ASK_TABLE");
if(mysqli_num_rows($sql) > 0) {
while($table = mysqli_fetch_assoc($sql)) {
echo "<br> " . $table["ROLLNO"] . " " . $table["NAME"] . " " .
$table["AGE"] . "";
}
}
mysqli_query($conn, "DELETE FROM ASK_TABLE
WHERE ROLLNO = 3");
Echo "<br>Table deleted: ";
mysqli_query($conn, "UPDATE ASK_TABLE SET AGE = 27
WHERE ROLLNO = 2");

echo "<br> <br>Table Updated:";


$sql = mysqli_query($conn, "SELECT *FROM ASK_TABLE");
if(mysqli_num_rows($sql) > 0) {
while($table = mysqli_fetch_assoc($sql)) {
echo "<br> " . $table["ROLLNO"] . " " . $table["NAME"] . " " .
$table["AGE"] . "";
}
}
mysqli_query($conn, "DROP TABLE ASK_TABLE");
mysqli_query($conn, "DROP DATABASE ASK_DB");
mysqli_close($conn);
?>
</html>

Output :
connected to mysql successfully...
Table Created:
1 ASHOK 20
2 CHARLES 34
3 PETER 25;

Table deleted:
Table Updated:
1 ASHOK 20
2 CHARLES 27
S. S. V. P. Sanstha’s
L. K. Dr. P. R. Ghogrey Science College, Dhule
Department of Computer Science
Lab on Internet Programming using PHP

Roll No. :- ____ Date: ___/___/2018


Name :- _________________________________________________

Assignment No-11) Write a PHP script to store, retrieve and delete cookies
on your local machine.

<?php
//create cookie- (30days*24hours*60minits*60seconds)
setcookie("cookie1", "ashok", time() + 30*24*60*60);
if(isset($_COOKIE['cookie1']))
echo $_COOKIE['cookie1'];
else
echo "cookie does not exist";

//retrieve cookie-
echo"<br>";
print_r($_COOKIE);
//update cookie-
setcookie("cookie2", "ashok1", time() + 30*24*60*60);

//retrieve cookie-
echo"<br>";
print_r($_COOKIE);
//delete cookie
setcookie("cookie2", "ashok", time() - 30*24*60*60);
?>

Output :
ashok
Array ( [PHPSESSID] => pnp9u49i0fgflq05huk9dnm92a [username] => ashok
[cookie1] => ashok )
Array ( [PHPSESSID] => pnp9u49i0fgflq05huk9dnm92a [username] => ashok
[cookie1] => ashok )
S. S. V. P. Sanstha’s
L. K. Dr. P. R. Ghogrey Science College, Dhule
Department of Computer Science
Lab on Internet Programming using PHP

Roll No. :- ____ Date: ___/___/2018


Name :- _________________________________________________

Assignment No-12) Write a PHP script to store, retrieve and delete data
using session variables.

<?php
session_start();
$_SESSION["rollno"] = 14;
$_SESSION["firstname"] = "ashok";
$_SESSION["lastname"] = "kumawat";

echo "<br>rollno : " . $_SESSION["rollno"];


echo "<br>name : " . $_SESSION["firstname"];
echo "<br>surname : " . $_SESSION["lastname"];

if(isset($_SESSION["lastname"]))
unset($_SESSION["lastname"]);

echo "<br> ";


print_r($_SESSION);
echo $_SESSION["lastname"];

session_destroy();
?>

Output :
rollno : 14
name : ashok
surname : kumawat
Array ( [rollno] => 14 [firstname] => ashok [lastname] => kumawat )
Array ( [rollno] => 14 [firstname] => ashok )
Notice: Undefined index: lastname in C:\xampp\htdocs\a_exp.php on line 23

You might also like