Tybsc Sem2 PHP Pract - Final - Set
Tybsc Sem2 PHP Pract - Final - Set
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 : ____
Assignment No-1) Design web pages using HTML that will contain online
admission forms.
<html>
<head>
<title> Admission Form</title>
</head>
Gender :
<input type="radio" name="gender" value="Male" checked="checked">Male
<input type="radio" name="gender" value="Female">Female
<br><br>
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>
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>
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>
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
<?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
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
<html>
<head>
<title>PHP Script For String demo</title>
</head>
<body>
<?php
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";
$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 :
<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 ";
?>
</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
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
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;
}
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 :
<html>
<head>
<title>PHP Script For OOPs Concepts</title>
</head>
<body>
<?php
interface interfc {
public function interfun();
}
?>
</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
<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
File 1 -
<html>
<head><title>TYBSc Addmision</title></head>
<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>
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
<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");
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
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
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";
if(isset($_SESSION["lastname"]))
unset($_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