SlideShare a Scribd company logo
1 of 54
UNIVERSAL GROUP OF
INSTITUTIONS!
Subject: PHP
Roll No: 2028783
SEM: 5th
Prepared By: Mr. Ali Jan Ehsani
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
2
Practical-1
AIM: - Create a php webpage and print “hello world”.
<Html>
<Head>
<Title> My Simple Program </Title>
</head>
<Body>
<?php
echo "Hello World"
?>
</Body>
</Html> O/P:
Hello World
Practical-2
AIM: - Create a php program to find odd or even number from given
number.
<Html>
<Head>
<Title> Find out odd or even number. . ! </title>
</Head >
<body>
<?php
$a = 10;
if ($a %
2==0)
{
echo "Given number is" . "<br>" . "<b>EVEN<b>" ;
}
else
{
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
3
echo "Given number is" . "<br>" . "<b>ODD<b>";
}
?>
</body> </html>
O/P:
Given number is EVEN
Practical-3
AIM: - Write a php program to find maximum of three numbers.
<html>
<head>
<title> Max out of three </title>
</head>
<body>
<?php
$a = 1;
$b = 4; $c
= 3; if($a
> $b)
{
if($a > $c)
echo "Maximum num a = $a";
else
echo "Maximum num c = $c";
}
else
{
if($c > $b)
echo "Maximum num c = $c";
else
echo "Maximum num b = $b";
}
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
4
?>
</body>
</html>
O/P:
Maximum num b =4
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
5
Practical-4
AIM: - Write a PHP program to swap two numbers.
<html>
<head>
<title>
Swapping of two numbers. . !
</title>
</head>
<Body>
<?php
$a = 10;
$b = 20;
echo "a = $a"."<br>"."b = $b"."<br>";
$a = $a + $b;
$b = $a - $b;
$a = $a - $b;
echo "<b>After Swapping"."<br>"." a = $a"."<br>"."b = $b<b>";
?>
</body>
</html>
O/P:
a =10 b =20 After Swapping a =20
b =10
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
6
Practical-5
5.1 AIM: - Write a PHP Program to demonstrate the variable function:
Gettype():
<html>
<head>
<title>
Variable function:gettype:1
</title>
</head>
<body>
<?php
$no = 5;
$value = 13.5;
$name = "Bipin R. Prajapati";
$var = true;
$myarray= array(110,45," Bipin",1.5,true);
echo gettype($no)."<br/>";
echo gettype($value)."<br/>"; echo
gettype($name)."<br/>"; echo
gettype($var)."<br/>";
echo gettype($myarray)."<br/>";
?>
</body>
</html>
O/P:
integer
double string
boolean
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
7
array
5.2 AIM: - Write a PHP Program to demonstrate the variable function:
Gettype():
<html>
<head>
<title> Variable function:gettype:2 </title>
</head>
<body>
<?php
$data = array(1,1.5,null,"Bipin",new stdclass,true);
foreach($data as $value)
{
echo gettype($value)."<br/>";
}
?>
</body>
</html>
O/P:
integer
double NULL
string object
boolean
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
8
Practical-6
AIM: Write a PHP Program to demonstrate the variable unction:
Settype()
<html>
<head>
<title> Variable function:Settype:1 </title> </head>
<body>
<?php
$var1 ="anil";
$var3 = "1Bipin";
$var4 = "anil1";
$var2 = true;
settype($var1, "integer");
settype($var2, "string"); settype($var3,
"integer"); settype($var4, "integer");
echo gettype($var1)."</br>";
echo gettype($var2)."</br>"; echo
gettype($var3)."</br>"; echo
gettype($var4)."</br>";
echo $var1."</br>";
echo $var2."</br>"; echo
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
9
$var3."</br>"; echo
$var4."</br>";
?>
</body>
</html>
O/P:
integer string
integer
integer
0
1
1
0
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
10
Practical-7
7.1 AIM: Write a PHP Program to demonstrate the variable unction:
isset()
<html>
<head>
<title> Variable function:isset:1 </title>
</head>
<body>
<?php
$no = 9;
$name = "Bipin";
$val=10.5;
echo isset($no)."</br>";
echo isset($name)."</br>";
echo isset($val)."</br>";
echo $no."</br>";
echo $name."</br>";
echo $val."</br>";
?>
</body>
</html> O/P:
1
1
1
9
Bipin
10.5
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 11
7.2 Write a PHP Program to demonstrate the variable unction:
isset()
<html>
<head>
<title>
Variable function:isset:2
</title>
</head>
<body>
<?php
$data = array('$no'=>9,'$name'=>"Bipin",'$marks'=>10.5)
foreach($data as $val1)
{
echo $val1."<br/>";
}
foreach($data as $val2)
{
echo isset($val2)."<br/>";
}
?>
</body>
</html>
O/P:
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 12
9
Bipin
10.5
1
1
1
Practical-8
8.1 AIM: Write a PHP Program to demonstrate the variable unction:
unset()
<html>
<head>
<title> Variable function:unset:1 </title>
</head>
<body>
<?php function unset_val1()
{
global $val1;
echo $val1;
unset($val1);
}
$val1 = "Bipin";
unset_val1();
?>
</body>
</html>
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 13
O/P:
Bipin
8.2 AIM: Write a PHP Program to demonstrate the variable unction:
unset()
<html>
<head>
<title> Variable function:unset:2 </title>
</head>
<body>
<?php function unset_val1()
{
global $val1;
echo $val1;
unset($GLOBALS['val1']);
}
$val1 = "Bipin";
unset_val1();
echo isset($val1);
echo $val1; ?> </body> </html>
O/P:
Bipin
( ! )
Notice: Undefined variable: val1 in C:wampwww@nil_09Pr-
8unset2.php line 19
on
Call Stack
# Time Memory Function Location
1 0.0007 365344 {main}( ) ..unset2.php:0
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 14
8.3 AIM: Write a PHP Program to demonstrate the variable unction:
unset()
<html>
<head>
<title> Variable function:unset:3 </title>
</head>
<body>
<?php function unset_static()
{
static $val1;
$val1++;
echo "Before unset(): $val1,";
unset($val1);
$val1 = 55;
echo "After unset(): $val1 <br/>";
}
unset_static();
unset_static(); unset_static();
?>
</body>
</html>
O/P:
Before unset(): 1,After unset(): 55
Before unset(): 2,After unset(): 55
Before unset(): 3,After unset(): 55
Practical-9
AIM:- Give the example of variable function:strval()
<html>
<head>
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 15
<title>
Variable Function:Strval()
</title>
</head>
<body>
<?php
$val1 = 22.110;
echo strval($val1);
?>
</body>
</html> O/P:
22.11
AIM:- Give the example of variable
function:floatval()
<html>
<head>
<title>
Variable Function:Floatval()
</title>
</head>
<body>
<?php
$val1 = "3.14pie";
echo floatval($val1);
?>
</body>
</html> O/P:
3.14
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 16
AIM:- Give the example of variable function:intval()
<html>
<head>
<title>
Variable Function:intval()
</title>
</head>
<body>
<?php
echo intval(102).'<br>'; echo
intval(102.22).'<br>'; echo intval('102').'<br>';
echo intval(+102).'<br>'; echo intval(-
102).'<br>'; echo intval(0102).'<br>'; echo
intval('0002').'<br>'; echo intval(1e20).'<br>';
echo intval(0x1B).'<br>'; echo
intval(10200000).'<br>'; echo
intval(10200000000000000000).'<br>'; echo
intval(10,2).'<br>';
echo intval('10',2).'<br>';
?>
</body>
</html>
O/P:
102
102
102
102
-102
66
2
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 17
0
27
10200000
0
10
2
Practical-10
AIM: - Give the example of variable function: print_r()
<html>
<head>
<title>
Variable Function:print_r()
</title>
</head>
<body>
<pre>
<?php
$data = array('e_no'=>106680307009,'e_name'=>'Bipin R.
Prajapati','S.P.I'=>array('1st'=>7.75,'2nd'=>8.27,'3rd'=>8.20,'4th'=>7.57));
print_r ($data);
?>
</pre>
</body>
</html>
O/P:
Array
(
[e_no] => 106680307009
[e_name] => Bipin R. Prajapati
[S.P.I] => Array
(
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 18
[1st] => 7.75
[2nd] => 8.27
[3rd] => 8.2
[4th] => 7.57
)
)
AIM:- Give the example of variable function:
var_dump()
<html>
<head>
<title>
Variable Function:var_dump()
</title>
</head>
<body>
<?php
$val1 = 678;
$val2 = "a678";
$val3 = "678";
$val4 = "BetterThanLike.com";
$val5 = 698.99; $val6 =
+125689.66; echo
var_dump($val1)."<br>"; echo
var_dump($val2)."<br>"; echo
var_dump($val3)."<br>"; echo
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 19
var_dump($val4)."<br>"; echo
var_dump($val5)."<br>"; echo
var_dump($val6)."<br>";
?>
</body>
</html>
O/P:
int 678
string 'a678' (length=4)
string '678' (length=3)
string 'BetterThanLike.com' (length=18)
float 698.99
float 125689.66
Practical-11
AIM: - Give the example of string function: substr():
<html>
<head>
<title> String Function:Substr():1 </title>
</head>
<body>
<b>If the start is non-negative, the returned string will start at the start'th position
in string, start from 0.</b><br/><br/>
<?php
echo "Substring with positive start:".substr("abcdef",2)."<br/>";?><br/>
<b>If the start is negative, the returned string will start at the start'th character in
string, from the end of the string.</b><br/><br/>
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 20
<?php
echo "Substring with negative start:".substr("abcdef",-2)."<br/>";?><br/>
<b>If the start is less than or equal to start characters long, false will
return</b><br/><br/> <?php
echo "start is <= string".substr("abcdef",7)."<br/><br/>";
echo "Finish";
?>
</body>
</html>
O/P:
If the start is non-negative, the returned string will start at the start'th position in
string, start from 0.
Substring with positive start:cdef
If the start is negative, the returned string will start at the start'th character in
string, from the end of the string.
Substring with negative start:ef
If the start is less than or equal to start characters long, false will return start
is <= string
Finish
AIM:- Give the example of string function:substr():2
<html>
<head>
<title> String Function:Substr():2 </title>
</head> <body>
<b>If the length is non-negative, the returned string will start at the start'th position
in string AND count the length.</b><br/><br/>
<?php
echo "Substring with positive length:".substr("abcdef",2,2)."<br/>";?></br>
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 21
<?php
echo "Substring with positive length:".substr("NBPATELPILUDARA",2,4)."<br/>";
?></br>
<?php
echo "Substring with positive length:".substr("abcdef",-3,2)."<br/>"; ?></br>
<?php
echo "Substring with positive
length:".substr("NBPATELPILUDARA",5,2)."<br/>";?></br>
<b>If the length is negative, the returned string will start at the start'th position in
string AND count the length.</b><br/><br/>
<?php
echo "Substring with negative length:".substr("abcdef",2,-2)."<br/>";?></br>
<?php
echo "Substring with negative
length:".substr("NBPATELPILUDARA",2,4)."<br/>";?></br>
<?php
echo "Substring with negative length:".substr("abcdef",-2,-2)."<br/>";?></br>
<?php
echo "Substring with negative length:".substr("NBPATELPILUDARA",-
2,4)."<br/>";?></br>
<?php
echo "Substring with negative length:".substr("NBPATELPILUDARA",-
4,2)."<br/>";?></br>
<?php
echo "Substring with negative length:".substr("NBPATELPILUDARA",-
5,4)."<br/>";?></br>
</body> </html>
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
22
O/P:
If the length is non-negative, the returned string will start at the start'th position in
string AND count the length.
Substring with positive length:cd
Substring with positive length:PATE
Substring with positive length:de
Substring with positive length:UD
If the length is negative, the returned string will start at the start'th position in
string AND count the length.
Substring with negative length:cd
Substring with negative length:PATELPILU
Substring with negative length:
Substring with negative length:
Substring with negative length:DA
Substring with negative length:U
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
23
AIM:- Give the example of string
function:substr():3
<<html>
<head>
<title> String Function: Substr():3 </title>
</head>
<body>
<?php
echo substr("Bipin R. Prajapati",0,1)."<br/>";
echo substr("Bipin R. Prajapati",1,3)."<br/>";
echo substr("Bipin R. Prajapati",5,2)."<br/>";
echo substr("Bipin R. Prajapati",8,9)."<br/>";
echo substr("Bipin R. Prajapati",-3,3)."<br/>";
echo substr("Bipin R. Prajapati",-9,-3)."<br/>";
echo substr("Bipin R. Prajapati",1,-10)."<br/>";
?>
</body>
</html>
O/P:
B
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
24
ipi
R Prajapat
ati
Prajap ipin
R.
Practical-12
AIM: - Give the example of string function: strcmp()
<html>
<head> <title> String Function:strcmp() </title> </head>
<body>
<?php
$str1 = 'a';
$str2 = 'b';
echo strcmp($str1, $str2)."<br/>";
$str3 = 'b';
$str4 = 'a';
echo strcmp($str3, $str4)."<br/>";
$str5 = "Anil";
$str6 = "anil";
echo strcmp($str5, $str6)."<br/>";
?>
</body></html> O/P:
-1
1
-1
AIM:- Give the example of string
function:strcasecmp()
<html>
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
25
<head> <title> String Function:strcasecmp() </title> </head>
<body>
<?php
$str1 = "Anil";
$str2 = "anil";
echo strcasecmp($str1, $str2)."<br/>";
$str3 = "anil";
$str4 = "anil";
echo strcasecmp($str3, $str4)."<br/>";
?>
</body> </html>
O/P:
0
0
Practical-13
AIM: - Give the example of string function: strpos():1
<html>
<head> <title>String Function:strpos():1</title> </head>
<body>
<?php
$string = "I am anil";
$pos = strpos($string,"nil");
if($pos === false)
{
echo "Not found.";
}
Else { echo "Found..!"; }
?>
</body> </html>
O/P:
Found..!
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
26
AIM:- Give the example of string
function:strpos():2
<html>
<head>
<title> String Function:strpos():2 </title>
</head>
<body>
<?php
$string = "I am anil";
$pos = strpos($string,"i");
if($pos === false)
{
echo "Not found.";
}
else {
echo "Found at $pos. .!";
}
?>
</body> </html> O/P:
Found at 7. .!
AIM:- Give the example of string
function:strpos():3
<html>
<head>
<title>
String Function:strpos():3
</title>
</head>
<body>
<?php
$string = "I am anil";
$pos = strpos($string,"a",3);
if($pos === false)
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
27
{
echo "Not found.";
}
else {
echo "Found at $pos. .!";
}
?>
</body>
</html>
O/P:
Found at 5. .!
Practical-14
AIM: - Write a PHP program that demonstrate form element(input
elements).
<html>
<head>
<title>general form</title>
</head>
<body bgcolor="aakk">
<form> Name:
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
28
<input type = "text" name = "txtname">
<br>
<br>
Roll no.:
<input type = "text" name = "txtr_no">
<br>
<br>
Hobby:<br>
<input type = "checkbox" name = "hobbies" value = "sport">
Reading <br/>
<input type = "checkbox" name = "hobbies" value = "sport">
Playing games <br/>
<input type = "checkbox" name = "hobbies" value = "sport">
internet surffing <br/> <br> Gender:
<input type = "radio" name = "Gender" value = "Male"> Male
<input type = "radio" name = "Gender" value = "Female"> Female
<br>
<br> Branch:
<select name = "Branches">
<option>C.E.</option>
<option>Mech</option>
<option>E.C.</option>
<option>I.T.</option>
<option>E.E.</option>
</select>
<br/>
<br>
<input type = "Submit" value = "Save">
<input type = "Reset" value = "Cancle">
</form>
</body>
</html> O/P:
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
29
Practical-15
AIM: - Write a PHP program that demonstrate passing variable using URL.
<html>
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
30
<head>
<title>Query String</title>
</head>
<body>
<form>
Hello Frendzz. . . !<br>
I am
<?php
echo $_GET["Name"];
echo $_GET["L_name"];
?>
</form>
</body>
</html>
O/P:
Localhost/@nil_09/querystr.php?Name=Bipin&L_name=Prajapati
Hello Frendzz. . . !
I am Bipin Prajapati
Practical-16
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
31
AIM: - Write a PHP program that demonstrate use of session:1
<html>
<head>
<title>Session</title>
</head> <body>
<?php
session_start();
$_SESSION["name"]="Anil";
$_SESSION["Password"]="nil";
?>
</body>
</html>
AIM:- Write a program that demonstrate use of session:2
<html>
<head>
<title>Session</title>
</head> <body>
<?php session_start(); echo
"Welcome ".$_SESSION["name"]."<br/>";
echo "your Password:".$_SESSION["Password"];
?>
</body>
</html>
O/P:
Welcome Anil
your Password: nil
Practical-17
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
32
AIM: - Write a program that demonstrate use of cookies: 1
<html>
<head>
<title>Examle of cookies. . !</title>
</head>
<body>
<?php
setcookie("name","Anil Basantani",time()+3600,"/","",0);
setcookie("age","21",time()+3600,"/","",0);
echo "set cookies";
?>
</body>
</html>
O/P:
set cookies
AIM:- Write a program that demonstrate use of cookies:2
<html>
<head>
<title>Access cookies. . !</title>
</head>
<body>
<?php
echo $_COOKIE["name"]."<br/>";
echo $_COOKIE["age"]."<br/>";
?>
</body>
</html>
O/P:
Anil Basantani
21
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
33
Practical-18
AIM: - Write a PHP program to create a database using MySQL.
<html>
<head>
<title>Create Database. </title>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die("not opened");
}
echo "Connection open"."</br>";
$query = "create database std";
$crdb = mysql_query($query,$con);
if(!$crdb)
{
die("not created. .!".mysql_error());
}
echo "database created.. !";
?>
</body>
</html>
O/P:
Connection open database
created.. !
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
34
PHP With MySQL (2360701) 6th CE
AIM: - Write a PHP
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
35
program to drop a database using MySQL.
<html>
<head>
<title>Drop Database. </title>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die("not opened");
}
echo "Connection open"."</br>";
$query = "drop database std";
$crdb = mysql_query($query,$con);
if(!$crdb)
{
die("not droped. .!" .mysql_error());
}
echo "database droped.. !";
?>
</body>
</html>
O/P:
Connection open database
droped.. !
PHP With MySQL (2360701) 6th CE
AIM: - Write a PHP
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
36
program to create a table in MySQL.
<html>
<head>
<title>Create Database. </title>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die("not opened");
}
echo "Connection open"."</br>";
$db = mysql_select_db("studinfo",$con);
if(!$db)
{
die("Database not found".mysql_error());
}
echo "Database is selected"."</br>";
$query = "create table computer(id INT not null,name varchar(50),branch
varchar(50))";
$crtb = mysql_query($query,$con);
if(!$crtb)
PHP With MySQL (2360701) 6th CE
AIM: - Write a PHP
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
37
{
die(" table not created. .!".mysql_error());
}
echo "table created.. !"."</br>";
?>
</body>
</html>
O/P:
Connection open
Database is selected table
created.. !
program to insert record into a table using MySQL.
<html>
<head>
<title>Create Database. </title>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die("not opened");
}
echo "Connection open"."</br>";
$db = mysql_select_db("studinfo",$con);
if(!$db)
{
die("Database not found".mysql_error());
PHP With MySQL (2360701) 6th CE
AIM: - Write a PHP
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
38
}
echo "Database is selected"."</br>";
$query = "insert into computer values(7009,'Anil J Basantani','Sadhana colony
Jamnagar')";
$insrtb = mysql_query($query,$con);
if(!$insrtb)
{
die("Record not inserted.".mysql_error());
}
echo "Record inserted successfully. . .!"."</br>";
?>
</body>
</html> O/P:
Connection open
Database is selected
Record inserted successfully. . .!
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
39
AIM:- Write a PHP program to drop table using MySQL.
<html>
<head>
<title>Create Database. </title>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die("not opened");
}
echo "Connection open"."</br>";
$db = mysql_select_db("studinfo",$con);
if(!$db)
{
die("Database not found".mysql_error());
}
echo "Database is selected"."</br>";
$query = "drop table ce";
$crtb = mysql_query($query,$con);
if(!$crtb)
{
die(" table not droped. .!".mysql_error());
}
echo "table droped.. !"."</br>";
?>
</body>
</html>
O/P:
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
40
Connection open
Database is selected table
droped.. !
AIM:- Write a program to update table:6
<html>
<head>
<title>Create Database. </title>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die("not opened");
}
echo "Connection open"."</br>";
$db = mysql_select_db("studinfo",$con);
if(!$db)
{
die("Database not found".mysql_error());
}
echo "Database is selected"."</br>";
$query = "update computer set id = 09 where id = 7009";
$crtb = mysql_query($query,$con);
if(!$crtb)
{
die(" table not updated. .!".mysql_error());
}
echo "table updated.. !"."</br>";
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
41
?>
</body>
</html>
O/P:
Connection open
Database is selected table
updated.. !
AIM:- Write a PHP program to select data and show into table format.
<html>
<head>
<title>Create Database. </title>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die("not opened");
}
echo "Connection open"."</br>";
$db = mysql_select_db("studinfo",$con);
if(!$db)
{
die("Database not found".mysql_error());
}
echo "Database is selected"."</br>";
$query = "select * from computer";
$sldt = mysql_query($query,$con);
if(!$sldt)
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
42
{
die("data not selected".mysql_error());
}
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Branch</th>
</tr>";
while($row = mysql_fetch_array($sldt))
{
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['branch']."</td>";
echo "</tr>";
}
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
43
echo "</table>";
?>
</body>
</html>
O/P:
Connection open
Database is selected
ID Name Branch
9 Anil J Basantani CE
9 Anil J Basantani CE
9 Anil J Basantani CE
Practical-19
AIM: - Create a student Registration in PHP and Save and Display the
student Records.
<html>
<head>
<title>general form</title>
</head>
<body bgcolor="aakk">
<form action = "<?php $_PHP_SELF ?>" method = "POST">
Name:
<input type = "text" name = "txtname">
<br><br>
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
44
Roll no.:
<input type = "text" name = "txtr_no">
<br><br>
Gender:
<input type = "text" name = "txtgen">
<br><br>
Address:
<textarea name = "add" type = "textarea"></textarea>
<br><br>
<input type = "Submit" name = "insert" value = "Save">
<input type = "Reset" value = "Cancle">
</form>
</body>
</html> <?php
if(isset($_POST['insert']))
{
$con = mysql_connect("localhost","root","");
if($con)
{
echo "Mysql connection ok<br>";
mysql_select_db("studinfo",$con);
$name = strval($_POST['txtname']);
$rollno = intval($_POST['txtr_no']);
$gender = strval($_POST['txtgen']);
$address = strval($_POST['add']);
$insert = "insert into info values('$name',$rollno,'$gender','$address')";
if(mysql_query($insert,$con))
{
echo "Data inserted successfully<br>";
}
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
45
$query = "select * from info";
$sldt = mysql_query($query,$con);
echo "<table border='1'>
<tr>
<th>Name</th>
<th>Roll No</th>
<th>Gender</th>
<th>Address</th>
</tr>";
while($row = mysql_fetch_array($sldt))
{
echo "<tr>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['rollno']."</td>"; echo
"<td>".$row['gen']."</td>"; echo
"<td>".$row['address']."</td>"; echo
"</tr>";
}
echo "</table>";
mysql_close($con);
}
}
?>
O/P:
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
46
PAPER SOLUTION
Extra-1
AIM: - Write a program to Develop student registration form and display
all the submitted data on another page.
Form fill.php
<html>
<head>
<title>insert data in form</title>
</head>
<body>
<form action = "getdata.php" method = "POST">
Name:
<input type = "text" name = "txtname">
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
47
<br><br>
Roll no.:
<input type = "text" name = "txtr_no">
<br><br>
Address:
<textarea name = "add" type = "textarea"></textarea>
<br><br>
Contyact No:
<input type = "text" name = "txtc_no">
<br><br>
Email ID:
<input type = "text" name = "txteid">
<br><br>
<input type = "Submit" name = "insert" value = "Save">
<input type = "Reset" value = "Cancle">
</form>
</body>
</html>
Getdata.php
<html>
<head>
<title>get data from another page</title>
</head>
<body>
<?php
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
48
echo "Name:" .$_POST["txtname"]."</br>";
echo "Roll no.:".$_POST["txtr_no"]."</br>"; echo
"Address:".$_POST["add"]."</br>"; echo
"Contact No.:".$_POST["txtc_no"]."</br>";
echo "Email ID:".$_POST["txteid"]."</br>";
?>
Extra-2
AIM: - Write a program to read customer information like c_no, c_name,
item_purchased and mob_no from customer table and display all this
information in table format on output screen.
</body>
</html>
O/P:
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
49
<html>
<head>
<title>display data in table format</title>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die("not connected".mysql_error());
}
echo "Connection open"."<br/>";
$sldb = mysql_select_db("coust",$con);
if(!$sldb)
{
die("not found".mysql_error());
}
echo "Database selected"."<br/>";
$query = "select * from customer";
$sql = mysql_query($query);
echo "<table border = '1'>
<tr>
<th>C_No</th>
<th>C_Name</th>
<th>Item_Purchased</th>
<th>Mob_no</th>
</tr>";
while($row = mysql_fetch_array($sql))
{
echo "<tr>";
echo "<td>".$row['c_no']."</td>"; echo
"<td>".$row['c_name']."</td>"; echo
"<td>".$row['item_purchased']."</td>"; echo
"<td>".$row['mob_no']."</td>";
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
50
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>
O/P:
Connection open
Database selected
C_No C_Name Item_Purchased Mob_no
1 Anil Book 2147483647
2 Yogesh Marker 2147483647
Extra-3
AIM: - Write PHP code to upload image.
<?php
$result=0;
if (trim($_POST["action"]) == "Upload File")
{
$imagename = basename($_FILES['image_file']['name']);
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $imagename);
if ($result==1) echo("Successfully uploaded: <b>".$imagename."</b>");
}
?>
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
51
<html>
<head>
<title>Upload file script</title>
</head>
<body>
<form method='POST' enctype='multipart/form-data' name='frmmain' >
Browse for Image (jpg): <input type="file" name="image_file" size="35">
<br>
<input type="submit" value=" Upload File " name="action">
</form>
<br>
<?php
if ($result==1) echo("<img src='".$imagename."'>");
?>
</body>
</html>
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
52
O/P
Browse for Image (jpg):
Upload
Extra-4
AIM: - Write a program that keeps track of how many times a visitor has
loaded the page.
<html>
<head>
<title>php counter</title>
</head>
<body>
<?php
session_start();
if(isset($_SESSION['counter']))
{
$_SESSION['counter'] += 1;
}
else
{
$_SESSION['counter'] = 1;
}
Upload
File
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
53
echo "You have visited this page ".$_SESSION['counter']." time in this session";
?>
</body>
</html>
O/P:
You have visited this page 1 time in this session
Extra-5
AIM: Write a program that displays a different message based on time of
day. For example page should display “Good Morning” if it is accessed in
the morning.
<?PHP
//Change the messages to what you want.
$afternoon = "Good afternoon! ";
$evening = "Good evening! ";
$late = "Working late? ";
$morning = "Good morning! ";
$friday= "Get ready for the weekend! ";
PHP With MySQL (2360701) 6th CE
N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati
54
//Get the current hour
$current_time = date('G');
//Get the current day
$current_day = date('l');
//12 p.m. - 4 p.m. if ($current_time >= 12 &&
$current_time <= 16) { echo $afternoon;
}
// 5 p.m. to 11 p.m. elseif ($current_time >= 17 &&
$current_time <= 24) { echo $evening;
}
//12 a.m. - 5 a.m. elseif ($current_time >= 1 &&
$current_time <= 5) { echo $late;
}
// 6 a.m. to 11 a.m. elseif ($current_time >= 6 &&
$current_time <= 11) { echo $morning;
}
//If it's Friday, display a message
if ($current_day == "Friday")
{
echo $friday;
}
?>
O/P :-
Good morning! (Its base on Current Time)

More Related Content

Similar to PHP-PRACTICALS

Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Michael Wales
 
PHP an intro -1
PHP an intro -1PHP an intro -1
PHP an intro -1Kanchilug
 
Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!Kacper Gunia
 
Developing for Business
Developing for BusinessDeveloping for Business
Developing for BusinessAntonio Spinelli
 
TDC2016SP - Trilha Developing for Business
TDC2016SP - Trilha Developing for BusinessTDC2016SP - Trilha Developing for Business
TDC2016SP - Trilha Developing for Businesstdc-globalcode
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowKacper Gunia
 
Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2markstory
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolveXSolve
 
Core Php Component Presentation
Core Php Component PresentationCore Php Component Presentation
Core Php Component PresentationJohn Coonen
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8PrinceGuru MS
 
Advanced PHPUnit Testing
Advanced PHPUnit TestingAdvanced PHPUnit Testing
Advanced PHPUnit TestingMike Lively
 
2009-02 Oops!
2009-02 Oops!2009-02 Oops!
2009-02 Oops!terry chay
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with PerlDave Cross
 
#SPUG - Legacy applications
#SPUG - Legacy applications#SPUG - Legacy applications
#SPUG - Legacy applicationsPiotr Pasich
 
Getting out of Callback Hell in PHP
Getting out of Callback Hell in PHPGetting out of Callback Hell in PHP
Getting out of Callback Hell in PHPArul Kumaran
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkDirk Haun
 
Legacy applications - 4Developes konferencja, Piotr Pasich
Legacy applications  - 4Developes konferencja, Piotr PasichLegacy applications  - 4Developes konferencja, Piotr Pasich
Legacy applications - 4Developes konferencja, Piotr PasichPiotr Pasich
 

Similar to PHP-PRACTICALS (20)

Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
 
PHP an intro -1
PHP an intro -1PHP an intro -1
PHP an intro -1
 
Html , php, mysql intro
Html , php, mysql introHtml , php, mysql intro
Html , php, mysql intro
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!
 
Developing for Business
Developing for BusinessDeveloping for Business
Developing for Business
 
TDC2016SP - Trilha Developing for Business
TDC2016SP - Trilha Developing for BusinessTDC2016SP - Trilha Developing for Business
TDC2016SP - Trilha Developing for Business
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
 
What's new with PHP7
What's new with PHP7What's new with PHP7
What's new with PHP7
 
Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
Core Php Component Presentation
Core Php Component PresentationCore Php Component Presentation
Core Php Component Presentation
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8
 
Advanced PHPUnit Testing
Advanced PHPUnit TestingAdvanced PHPUnit Testing
Advanced PHPUnit Testing
 
2009-02 Oops!
2009-02 Oops!2009-02 Oops!
2009-02 Oops!
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
#SPUG - Legacy applications
#SPUG - Legacy applications#SPUG - Legacy applications
#SPUG - Legacy applications
 
Getting out of Callback Hell in PHP
Getting out of Callback Hell in PHPGetting out of Callback Hell in PHP
Getting out of Callback Hell in PHP
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
Legacy applications - 4Developes konferencja, Piotr Pasich
Legacy applications  - 4Developes konferencja, Piotr PasichLegacy applications  - 4Developes konferencja, Piotr Pasich
Legacy applications - 4Developes konferencja, Piotr Pasich
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...Pooja Nehwal
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Dr. Mazin Mohamed alkathiri
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 

Recently uploaded (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 

PHP-PRACTICALS

  • 1. UNIVERSAL GROUP OF INSTITUTIONS! Subject: PHP Roll No: 2028783 SEM: 5th Prepared By: Mr. Ali Jan Ehsani
  • 2. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 2 Practical-1 AIM: - Create a php webpage and print “hello world”. <Html> <Head> <Title> My Simple Program </Title> </head> <Body> <?php echo "Hello World" ?> </Body> </Html> O/P: Hello World Practical-2 AIM: - Create a php program to find odd or even number from given number. <Html> <Head> <Title> Find out odd or even number. . ! </title> </Head > <body> <?php $a = 10; if ($a % 2==0) { echo "Given number is" . "<br>" . "<b>EVEN<b>" ; } else {
  • 3. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 3 echo "Given number is" . "<br>" . "<b>ODD<b>"; } ?> </body> </html> O/P: Given number is EVEN Practical-3 AIM: - Write a php program to find maximum of three numbers. <html> <head> <title> Max out of three </title> </head> <body> <?php $a = 1; $b = 4; $c = 3; if($a > $b) { if($a > $c) echo "Maximum num a = $a"; else echo "Maximum num c = $c"; } else { if($c > $b) echo "Maximum num c = $c"; else echo "Maximum num b = $b"; }
  • 4. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 4 ?> </body> </html> O/P: Maximum num b =4
  • 5. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 5 Practical-4 AIM: - Write a PHP program to swap two numbers. <html> <head> <title> Swapping of two numbers. . ! </title> </head> <Body> <?php $a = 10; $b = 20; echo "a = $a"."<br>"."b = $b"."<br>"; $a = $a + $b; $b = $a - $b; $a = $a - $b; echo "<b>After Swapping"."<br>"." a = $a"."<br>"."b = $b<b>"; ?> </body> </html> O/P: a =10 b =20 After Swapping a =20 b =10
  • 6. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 6 Practical-5 5.1 AIM: - Write a PHP Program to demonstrate the variable function: Gettype(): <html> <head> <title> Variable function:gettype:1 </title> </head> <body> <?php $no = 5; $value = 13.5; $name = "Bipin R. Prajapati"; $var = true; $myarray= array(110,45," Bipin",1.5,true); echo gettype($no)."<br/>"; echo gettype($value)."<br/>"; echo gettype($name)."<br/>"; echo gettype($var)."<br/>"; echo gettype($myarray)."<br/>"; ?> </body> </html> O/P: integer double string boolean
  • 7. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 7 array 5.2 AIM: - Write a PHP Program to demonstrate the variable function: Gettype(): <html> <head> <title> Variable function:gettype:2 </title> </head> <body> <?php $data = array(1,1.5,null,"Bipin",new stdclass,true); foreach($data as $value) { echo gettype($value)."<br/>"; } ?> </body> </html> O/P: integer double NULL string object boolean
  • 8. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 8 Practical-6 AIM: Write a PHP Program to demonstrate the variable unction: Settype() <html> <head> <title> Variable function:Settype:1 </title> </head> <body> <?php $var1 ="anil"; $var3 = "1Bipin"; $var4 = "anil1"; $var2 = true; settype($var1, "integer"); settype($var2, "string"); settype($var3, "integer"); settype($var4, "integer"); echo gettype($var1)."</br>"; echo gettype($var2)."</br>"; echo gettype($var3)."</br>"; echo gettype($var4)."</br>"; echo $var1."</br>"; echo $var2."</br>"; echo
  • 9. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 9 $var3."</br>"; echo $var4."</br>"; ?> </body> </html> O/P: integer string integer integer 0 1 1 0
  • 10. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 10 Practical-7 7.1 AIM: Write a PHP Program to demonstrate the variable unction: isset() <html> <head> <title> Variable function:isset:1 </title> </head> <body> <?php $no = 9; $name = "Bipin"; $val=10.5; echo isset($no)."</br>"; echo isset($name)."</br>"; echo isset($val)."</br>"; echo $no."</br>"; echo $name."</br>"; echo $val."</br>"; ?> </body> </html> O/P: 1 1 1 9 Bipin 10.5
  • 11. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 11 7.2 Write a PHP Program to demonstrate the variable unction: isset() <html> <head> <title> Variable function:isset:2 </title> </head> <body> <?php $data = array('$no'=>9,'$name'=>"Bipin",'$marks'=>10.5) foreach($data as $val1) { echo $val1."<br/>"; } foreach($data as $val2) { echo isset($val2)."<br/>"; } ?> </body> </html> O/P:
  • 12. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 12 9 Bipin 10.5 1 1 1 Practical-8 8.1 AIM: Write a PHP Program to demonstrate the variable unction: unset() <html> <head> <title> Variable function:unset:1 </title> </head> <body> <?php function unset_val1() { global $val1; echo $val1; unset($val1); } $val1 = "Bipin"; unset_val1(); ?> </body> </html>
  • 13. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 13 O/P: Bipin 8.2 AIM: Write a PHP Program to demonstrate the variable unction: unset() <html> <head> <title> Variable function:unset:2 </title> </head> <body> <?php function unset_val1() { global $val1; echo $val1; unset($GLOBALS['val1']); } $val1 = "Bipin"; unset_val1(); echo isset($val1); echo $val1; ?> </body> </html> O/P: Bipin ( ! ) Notice: Undefined variable: val1 in C:wampwww@nil_09Pr- 8unset2.php line 19 on Call Stack # Time Memory Function Location 1 0.0007 365344 {main}( ) ..unset2.php:0
  • 14. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 14 8.3 AIM: Write a PHP Program to demonstrate the variable unction: unset() <html> <head> <title> Variable function:unset:3 </title> </head> <body> <?php function unset_static() { static $val1; $val1++; echo "Before unset(): $val1,"; unset($val1); $val1 = 55; echo "After unset(): $val1 <br/>"; } unset_static(); unset_static(); unset_static(); ?> </body> </html> O/P: Before unset(): 1,After unset(): 55 Before unset(): 2,After unset(): 55 Before unset(): 3,After unset(): 55 Practical-9 AIM:- Give the example of variable function:strval() <html> <head>
  • 15. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 15 <title> Variable Function:Strval() </title> </head> <body> <?php $val1 = 22.110; echo strval($val1); ?> </body> </html> O/P: 22.11 AIM:- Give the example of variable function:floatval() <html> <head> <title> Variable Function:Floatval() </title> </head> <body> <?php $val1 = "3.14pie"; echo floatval($val1); ?> </body> </html> O/P: 3.14
  • 16. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 16 AIM:- Give the example of variable function:intval() <html> <head> <title> Variable Function:intval() </title> </head> <body> <?php echo intval(102).'<br>'; echo intval(102.22).'<br>'; echo intval('102').'<br>'; echo intval(+102).'<br>'; echo intval(- 102).'<br>'; echo intval(0102).'<br>'; echo intval('0002').'<br>'; echo intval(1e20).'<br>'; echo intval(0x1B).'<br>'; echo intval(10200000).'<br>'; echo intval(10200000000000000000).'<br>'; echo intval(10,2).'<br>'; echo intval('10',2).'<br>'; ?> </body> </html> O/P: 102 102 102 102 -102 66 2
  • 17. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 17 0 27 10200000 0 10 2 Practical-10 AIM: - Give the example of variable function: print_r() <html> <head> <title> Variable Function:print_r() </title> </head> <body> <pre> <?php $data = array('e_no'=>106680307009,'e_name'=>'Bipin R. Prajapati','S.P.I'=>array('1st'=>7.75,'2nd'=>8.27,'3rd'=>8.20,'4th'=>7.57)); print_r ($data); ?> </pre> </body> </html> O/P: Array ( [e_no] => 106680307009 [e_name] => Bipin R. Prajapati [S.P.I] => Array (
  • 18. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 18 [1st] => 7.75 [2nd] => 8.27 [3rd] => 8.2 [4th] => 7.57 ) ) AIM:- Give the example of variable function: var_dump() <html> <head> <title> Variable Function:var_dump() </title> </head> <body> <?php $val1 = 678; $val2 = "a678"; $val3 = "678"; $val4 = "BetterThanLike.com"; $val5 = 698.99; $val6 = +125689.66; echo var_dump($val1)."<br>"; echo var_dump($val2)."<br>"; echo var_dump($val3)."<br>"; echo
  • 19. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 19 var_dump($val4)."<br>"; echo var_dump($val5)."<br>"; echo var_dump($val6)."<br>"; ?> </body> </html> O/P: int 678 string 'a678' (length=4) string '678' (length=3) string 'BetterThanLike.com' (length=18) float 698.99 float 125689.66 Practical-11 AIM: - Give the example of string function: substr(): <html> <head> <title> String Function:Substr():1 </title> </head> <body> <b>If the start is non-negative, the returned string will start at the start'th position in string, start from 0.</b><br/><br/> <?php echo "Substring with positive start:".substr("abcdef",2)."<br/>";?><br/> <b>If the start is negative, the returned string will start at the start'th character in string, from the end of the string.</b><br/><br/>
  • 20. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 20 <?php echo "Substring with negative start:".substr("abcdef",-2)."<br/>";?><br/> <b>If the start is less than or equal to start characters long, false will return</b><br/><br/> <?php echo "start is <= string".substr("abcdef",7)."<br/><br/>"; echo "Finish"; ?> </body> </html> O/P: If the start is non-negative, the returned string will start at the start'th position in string, start from 0. Substring with positive start:cdef If the start is negative, the returned string will start at the start'th character in string, from the end of the string. Substring with negative start:ef If the start is less than or equal to start characters long, false will return start is <= string Finish AIM:- Give the example of string function:substr():2 <html> <head> <title> String Function:Substr():2 </title> </head> <body> <b>If the length is non-negative, the returned string will start at the start'th position in string AND count the length.</b><br/><br/> <?php echo "Substring with positive length:".substr("abcdef",2,2)."<br/>";?></br>
  • 21. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 21 <?php echo "Substring with positive length:".substr("NBPATELPILUDARA",2,4)."<br/>"; ?></br> <?php echo "Substring with positive length:".substr("abcdef",-3,2)."<br/>"; ?></br> <?php echo "Substring with positive length:".substr("NBPATELPILUDARA",5,2)."<br/>";?></br> <b>If the length is negative, the returned string will start at the start'th position in string AND count the length.</b><br/><br/> <?php echo "Substring with negative length:".substr("abcdef",2,-2)."<br/>";?></br> <?php echo "Substring with negative length:".substr("NBPATELPILUDARA",2,4)."<br/>";?></br> <?php echo "Substring with negative length:".substr("abcdef",-2,-2)."<br/>";?></br> <?php echo "Substring with negative length:".substr("NBPATELPILUDARA",- 2,4)."<br/>";?></br> <?php echo "Substring with negative length:".substr("NBPATELPILUDARA",- 4,2)."<br/>";?></br> <?php echo "Substring with negative length:".substr("NBPATELPILUDARA",- 5,4)."<br/>";?></br> </body> </html>
  • 22. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 22 O/P: If the length is non-negative, the returned string will start at the start'th position in string AND count the length. Substring with positive length:cd Substring with positive length:PATE Substring with positive length:de Substring with positive length:UD If the length is negative, the returned string will start at the start'th position in string AND count the length. Substring with negative length:cd Substring with negative length:PATELPILU Substring with negative length: Substring with negative length: Substring with negative length:DA Substring with negative length:U
  • 23. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 23 AIM:- Give the example of string function:substr():3 <<html> <head> <title> String Function: Substr():3 </title> </head> <body> <?php echo substr("Bipin R. Prajapati",0,1)."<br/>"; echo substr("Bipin R. Prajapati",1,3)."<br/>"; echo substr("Bipin R. Prajapati",5,2)."<br/>"; echo substr("Bipin R. Prajapati",8,9)."<br/>"; echo substr("Bipin R. Prajapati",-3,3)."<br/>"; echo substr("Bipin R. Prajapati",-9,-3)."<br/>"; echo substr("Bipin R. Prajapati",1,-10)."<br/>"; ?> </body> </html> O/P: B
  • 24. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 24 ipi R Prajapat ati Prajap ipin R. Practical-12 AIM: - Give the example of string function: strcmp() <html> <head> <title> String Function:strcmp() </title> </head> <body> <?php $str1 = 'a'; $str2 = 'b'; echo strcmp($str1, $str2)."<br/>"; $str3 = 'b'; $str4 = 'a'; echo strcmp($str3, $str4)."<br/>"; $str5 = "Anil"; $str6 = "anil"; echo strcmp($str5, $str6)."<br/>"; ?> </body></html> O/P: -1 1 -1 AIM:- Give the example of string function:strcasecmp() <html>
  • 25. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 25 <head> <title> String Function:strcasecmp() </title> </head> <body> <?php $str1 = "Anil"; $str2 = "anil"; echo strcasecmp($str1, $str2)."<br/>"; $str3 = "anil"; $str4 = "anil"; echo strcasecmp($str3, $str4)."<br/>"; ?> </body> </html> O/P: 0 0 Practical-13 AIM: - Give the example of string function: strpos():1 <html> <head> <title>String Function:strpos():1</title> </head> <body> <?php $string = "I am anil"; $pos = strpos($string,"nil"); if($pos === false) { echo "Not found."; } Else { echo "Found..!"; } ?> </body> </html> O/P: Found..!
  • 26. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 26 AIM:- Give the example of string function:strpos():2 <html> <head> <title> String Function:strpos():2 </title> </head> <body> <?php $string = "I am anil"; $pos = strpos($string,"i"); if($pos === false) { echo "Not found."; } else { echo "Found at $pos. .!"; } ?> </body> </html> O/P: Found at 7. .! AIM:- Give the example of string function:strpos():3 <html> <head> <title> String Function:strpos():3 </title> </head> <body> <?php $string = "I am anil"; $pos = strpos($string,"a",3); if($pos === false)
  • 27. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 27 { echo "Not found."; } else { echo "Found at $pos. .!"; } ?> </body> </html> O/P: Found at 5. .! Practical-14 AIM: - Write a PHP program that demonstrate form element(input elements). <html> <head> <title>general form</title> </head> <body bgcolor="aakk"> <form> Name:
  • 28. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 28 <input type = "text" name = "txtname"> <br> <br> Roll no.: <input type = "text" name = "txtr_no"> <br> <br> Hobby:<br> <input type = "checkbox" name = "hobbies" value = "sport"> Reading <br/> <input type = "checkbox" name = "hobbies" value = "sport"> Playing games <br/> <input type = "checkbox" name = "hobbies" value = "sport"> internet surffing <br/> <br> Gender: <input type = "radio" name = "Gender" value = "Male"> Male <input type = "radio" name = "Gender" value = "Female"> Female <br> <br> Branch: <select name = "Branches"> <option>C.E.</option> <option>Mech</option> <option>E.C.</option> <option>I.T.</option> <option>E.E.</option> </select> <br/> <br> <input type = "Submit" value = "Save"> <input type = "Reset" value = "Cancle"> </form> </body> </html> O/P:
  • 29. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 29 Practical-15 AIM: - Write a PHP program that demonstrate passing variable using URL. <html>
  • 30. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 30 <head> <title>Query String</title> </head> <body> <form> Hello Frendzz. . . !<br> I am <?php echo $_GET["Name"]; echo $_GET["L_name"]; ?> </form> </body> </html> O/P: Localhost/@nil_09/querystr.php?Name=Bipin&L_name=Prajapati Hello Frendzz. . . ! I am Bipin Prajapati Practical-16
  • 31. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 31 AIM: - Write a PHP program that demonstrate use of session:1 <html> <head> <title>Session</title> </head> <body> <?php session_start(); $_SESSION["name"]="Anil"; $_SESSION["Password"]="nil"; ?> </body> </html> AIM:- Write a program that demonstrate use of session:2 <html> <head> <title>Session</title> </head> <body> <?php session_start(); echo "Welcome ".$_SESSION["name"]."<br/>"; echo "your Password:".$_SESSION["Password"]; ?> </body> </html> O/P: Welcome Anil your Password: nil Practical-17
  • 32. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 32 AIM: - Write a program that demonstrate use of cookies: 1 <html> <head> <title>Examle of cookies. . !</title> </head> <body> <?php setcookie("name","Anil Basantani",time()+3600,"/","",0); setcookie("age","21",time()+3600,"/","",0); echo "set cookies"; ?> </body> </html> O/P: set cookies AIM:- Write a program that demonstrate use of cookies:2 <html> <head> <title>Access cookies. . !</title> </head> <body> <?php echo $_COOKIE["name"]."<br/>"; echo $_COOKIE["age"]."<br/>"; ?> </body> </html> O/P: Anil Basantani 21
  • 33. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 33 Practical-18 AIM: - Write a PHP program to create a database using MySQL. <html> <head> <title>Create Database. </title> </head> <body> <?php $con = mysql_connect("localhost","root",""); if(!$con) { die("not opened"); } echo "Connection open"."</br>"; $query = "create database std"; $crdb = mysql_query($query,$con); if(!$crdb) { die("not created. .!".mysql_error()); } echo "database created.. !"; ?> </body> </html> O/P: Connection open database created.. !
  • 34. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 34
  • 35. PHP With MySQL (2360701) 6th CE AIM: - Write a PHP N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 35 program to drop a database using MySQL. <html> <head> <title>Drop Database. </title> </head> <body> <?php $con = mysql_connect("localhost","root",""); if(!$con) { die("not opened"); } echo "Connection open"."</br>"; $query = "drop database std"; $crdb = mysql_query($query,$con); if(!$crdb) { die("not droped. .!" .mysql_error()); } echo "database droped.. !"; ?> </body> </html> O/P: Connection open database droped.. !
  • 36. PHP With MySQL (2360701) 6th CE AIM: - Write a PHP N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 36 program to create a table in MySQL. <html> <head> <title>Create Database. </title> </head> <body> <?php $con = mysql_connect("localhost","root",""); if(!$con) { die("not opened"); } echo "Connection open"."</br>"; $db = mysql_select_db("studinfo",$con); if(!$db) { die("Database not found".mysql_error()); } echo "Database is selected"."</br>"; $query = "create table computer(id INT not null,name varchar(50),branch varchar(50))"; $crtb = mysql_query($query,$con); if(!$crtb)
  • 37. PHP With MySQL (2360701) 6th CE AIM: - Write a PHP N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 37 { die(" table not created. .!".mysql_error()); } echo "table created.. !"."</br>"; ?> </body> </html> O/P: Connection open Database is selected table created.. ! program to insert record into a table using MySQL. <html> <head> <title>Create Database. </title> </head> <body> <?php $con = mysql_connect("localhost","root",""); if(!$con) { die("not opened"); } echo "Connection open"."</br>"; $db = mysql_select_db("studinfo",$con); if(!$db) { die("Database not found".mysql_error());
  • 38. PHP With MySQL (2360701) 6th CE AIM: - Write a PHP N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 38 } echo "Database is selected"."</br>"; $query = "insert into computer values(7009,'Anil J Basantani','Sadhana colony Jamnagar')"; $insrtb = mysql_query($query,$con); if(!$insrtb) { die("Record not inserted.".mysql_error()); } echo "Record inserted successfully. . .!"."</br>"; ?> </body> </html> O/P: Connection open Database is selected Record inserted successfully. . .!
  • 39. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 39 AIM:- Write a PHP program to drop table using MySQL. <html> <head> <title>Create Database. </title> </head> <body> <?php $con = mysql_connect("localhost","root",""); if(!$con) { die("not opened"); } echo "Connection open"."</br>"; $db = mysql_select_db("studinfo",$con); if(!$db) { die("Database not found".mysql_error()); } echo "Database is selected"."</br>"; $query = "drop table ce"; $crtb = mysql_query($query,$con); if(!$crtb) { die(" table not droped. .!".mysql_error()); } echo "table droped.. !"."</br>"; ?> </body> </html> O/P:
  • 40. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 40 Connection open Database is selected table droped.. ! AIM:- Write a program to update table:6 <html> <head> <title>Create Database. </title> </head> <body> <?php $con = mysql_connect("localhost","root",""); if(!$con) { die("not opened"); } echo "Connection open"."</br>"; $db = mysql_select_db("studinfo",$con); if(!$db) { die("Database not found".mysql_error()); } echo "Database is selected"."</br>"; $query = "update computer set id = 09 where id = 7009"; $crtb = mysql_query($query,$con); if(!$crtb) { die(" table not updated. .!".mysql_error()); } echo "table updated.. !"."</br>";
  • 41. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 41 ?> </body> </html> O/P: Connection open Database is selected table updated.. ! AIM:- Write a PHP program to select data and show into table format. <html> <head> <title>Create Database. </title> </head> <body> <?php $con = mysql_connect("localhost","root",""); if(!$con) { die("not opened"); } echo "Connection open"."</br>"; $db = mysql_select_db("studinfo",$con); if(!$db) { die("Database not found".mysql_error()); } echo "Database is selected"."</br>"; $query = "select * from computer"; $sldt = mysql_query($query,$con); if(!$sldt)
  • 42. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 42 { die("data not selected".mysql_error()); } echo "<table border='1'> <tr> <th>ID</th> <th>Name</th> <th>Branch</th> </tr>"; while($row = mysql_fetch_array($sldt)) { echo "<tr>"; echo "<td>".$row['id']."</td>"; echo "<td>".$row['name']."</td>"; echo "<td>".$row['branch']."</td>"; echo "</tr>"; }
  • 43. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 43 echo "</table>"; ?> </body> </html> O/P: Connection open Database is selected ID Name Branch 9 Anil J Basantani CE 9 Anil J Basantani CE 9 Anil J Basantani CE Practical-19 AIM: - Create a student Registration in PHP and Save and Display the student Records. <html> <head> <title>general form</title> </head> <body bgcolor="aakk"> <form action = "<?php $_PHP_SELF ?>" method = "POST"> Name: <input type = "text" name = "txtname"> <br><br>
  • 44. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 44 Roll no.: <input type = "text" name = "txtr_no"> <br><br> Gender: <input type = "text" name = "txtgen"> <br><br> Address: <textarea name = "add" type = "textarea"></textarea> <br><br> <input type = "Submit" name = "insert" value = "Save"> <input type = "Reset" value = "Cancle"> </form> </body> </html> <?php if(isset($_POST['insert'])) { $con = mysql_connect("localhost","root",""); if($con) { echo "Mysql connection ok<br>"; mysql_select_db("studinfo",$con); $name = strval($_POST['txtname']); $rollno = intval($_POST['txtr_no']); $gender = strval($_POST['txtgen']); $address = strval($_POST['add']); $insert = "insert into info values('$name',$rollno,'$gender','$address')"; if(mysql_query($insert,$con)) { echo "Data inserted successfully<br>"; }
  • 45. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 45 $query = "select * from info"; $sldt = mysql_query($query,$con); echo "<table border='1'> <tr> <th>Name</th> <th>Roll No</th> <th>Gender</th> <th>Address</th> </tr>"; while($row = mysql_fetch_array($sldt)) { echo "<tr>"; echo "<td>".$row['name']."</td>"; echo "<td>".$row['rollno']."</td>"; echo "<td>".$row['gen']."</td>"; echo "<td>".$row['address']."</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); } } ?> O/P:
  • 46. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 46 PAPER SOLUTION Extra-1 AIM: - Write a program to Develop student registration form and display all the submitted data on another page. Form fill.php <html> <head> <title>insert data in form</title> </head> <body> <form action = "getdata.php" method = "POST"> Name: <input type = "text" name = "txtname">
  • 47. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 47 <br><br> Roll no.: <input type = "text" name = "txtr_no"> <br><br> Address: <textarea name = "add" type = "textarea"></textarea> <br><br> Contyact No: <input type = "text" name = "txtc_no"> <br><br> Email ID: <input type = "text" name = "txteid"> <br><br> <input type = "Submit" name = "insert" value = "Save"> <input type = "Reset" value = "Cancle"> </form> </body> </html> Getdata.php <html> <head> <title>get data from another page</title> </head> <body> <?php
  • 48. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 48 echo "Name:" .$_POST["txtname"]."</br>"; echo "Roll no.:".$_POST["txtr_no"]."</br>"; echo "Address:".$_POST["add"]."</br>"; echo "Contact No.:".$_POST["txtc_no"]."</br>"; echo "Email ID:".$_POST["txteid"]."</br>"; ?> Extra-2 AIM: - Write a program to read customer information like c_no, c_name, item_purchased and mob_no from customer table and display all this information in table format on output screen. </body> </html> O/P:
  • 49. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 49 <html> <head> <title>display data in table format</title> </head> <body> <?php $con = mysql_connect("localhost","root",""); if(!$con) { die("not connected".mysql_error()); } echo "Connection open"."<br/>"; $sldb = mysql_select_db("coust",$con); if(!$sldb) { die("not found".mysql_error()); } echo "Database selected"."<br/>"; $query = "select * from customer"; $sql = mysql_query($query); echo "<table border = '1'> <tr> <th>C_No</th> <th>C_Name</th> <th>Item_Purchased</th> <th>Mob_no</th> </tr>"; while($row = mysql_fetch_array($sql)) { echo "<tr>"; echo "<td>".$row['c_no']."</td>"; echo "<td>".$row['c_name']."</td>"; echo "<td>".$row['item_purchased']."</td>"; echo "<td>".$row['mob_no']."</td>";
  • 50. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 50 echo "</tr>"; } echo "</table>"; ?> </body> </html> O/P: Connection open Database selected C_No C_Name Item_Purchased Mob_no 1 Anil Book 2147483647 2 Yogesh Marker 2147483647 Extra-3 AIM: - Write PHP code to upload image. <?php $result=0; if (trim($_POST["action"]) == "Upload File") { $imagename = basename($_FILES['image_file']['name']); $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $imagename); if ($result==1) echo("Successfully uploaded: <b>".$imagename."</b>"); } ?>
  • 51. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 51 <html> <head> <title>Upload file script</title> </head> <body> <form method='POST' enctype='multipart/form-data' name='frmmain' > Browse for Image (jpg): <input type="file" name="image_file" size="35"> <br> <input type="submit" value=" Upload File " name="action"> </form> <br> <?php if ($result==1) echo("<img src='".$imagename."'>"); ?> </body> </html>
  • 52. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 52 O/P Browse for Image (jpg): Upload Extra-4 AIM: - Write a program that keeps track of how many times a visitor has loaded the page. <html> <head> <title>php counter</title> </head> <body> <?php session_start(); if(isset($_SESSION['counter'])) { $_SESSION['counter'] += 1; } else { $_SESSION['counter'] = 1; } Upload File
  • 53. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 53 echo "You have visited this page ".$_SESSION['counter']." time in this session"; ?> </body> </html> O/P: You have visited this page 1 time in this session Extra-5 AIM: Write a program that displays a different message based on time of day. For example page should display “Good Morning” if it is accessed in the morning. <?PHP //Change the messages to what you want. $afternoon = "Good afternoon! "; $evening = "Good evening! "; $late = "Working late? "; $morning = "Good morning! "; $friday= "Get ready for the weekend! ";
  • 54. PHP With MySQL (2360701) 6th CE N. B. Patel Polytechnic, Piludara Prepared By: Bipin Prajapati 54 //Get the current hour $current_time = date('G'); //Get the current day $current_day = date('l'); //12 p.m. - 4 p.m. if ($current_time >= 12 && $current_time <= 16) { echo $afternoon; } // 5 p.m. to 11 p.m. elseif ($current_time >= 17 && $current_time <= 24) { echo $evening; } //12 a.m. - 5 a.m. elseif ($current_time >= 1 && $current_time <= 5) { echo $late; } // 6 a.m. to 11 a.m. elseif ($current_time >= 6 && $current_time <= 11) { echo $morning; } //If it's Friday, display a message if ($current_day == "Friday") { echo $friday; } ?> O/P :- Good morning! (Its base on Current Time)