0% found this document useful (0 votes)
10 views84 pages

PHP Solved Slips

Uploaded by

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

PHP Solved Slips

Uploaded by

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

Q1)Wr i

teaPHPscr i
ptforthefoll
owing:Designaf ormto
acceptast r
ing.Writ
eaf uncti
ontocountt hetotalnumberof
vowels(a,e,
i,
o,u)f
rom thestri
ng.Showt heoccur rencesof
eachvowelf rom t
hestring.Checkwhet herthegivenst r
ingis
apal i
ndromeornot ,wi
thoutusingbuilt
-infunct
ion.( Useradi
o
buttonsandt heconceptoffuncti
on.Use‘ i
nclude’ const
ructor
requir
est mt.
)
Ans:
sl
ip1.
html(
fi
lenamesvaeasXammp-
>ht
docsf
loder
)
Eg.C:
\xampp\ht
docs\
rav
i)

<ht
ml>

<body
>

<f
orm act
ion="
sli
p.php"met
hod="
post
">

<h3>EnterSt
ing:<i
nputt
ype="
tex
t"name="
str
"
maxlength="
20"></
h3>

<h4>Oper
ti
ons:
</h4>

<i
nputt
ype="
radi
o"name="
op"v
alue="
1">Tot
alVowel
s<br
>

<i
nputt
ype="
radi
o"name="
op"v
alue="
2">Occur
ances<br
><br
>

<i
nputtype="
radi
o"name="
op"v
alue="
3">CheckSt
ri
ngi
s
Pal
indr
om orNot<br
><br
>

<i
nputt
ype="
submi
t"v
alue="
show"
>

</
for
m>

</
body
>

</
html
>

Sl
ip.
php
<?
php
f
unct
ioncnt
_ v
owels(
$a,
$l
)
{
$v_cnt=0;

f
or($i
=0;$i<$l ;
$i++){
i
f(
($a[$i
]=='a')||
($a[ $i
]==' e'
)|| (
$a[$i]==' i
'
)| |($a[$i
]=='o')||
(
$a[$i
]=='u'
)||($a[$i]=='A'
)| |($a[$i]=='E')||($a[$i]=='
I'
)||
(
$a[$i
]=='O'
)||($a[ $i
]=='U'))$v _cnt++;
}
return$v_ cnt;
}
f
unctionoccur _
vowel s($a,$l)
{
$av =$ev=$i v
=$ov =$uv =$cnt =0;
for($i
=0;$i<$l;$i++)
{
i
f (
($a[ $i
]==' a')|
|( $a[$i
]=='A'))
$av ++;
elseif(($a[$i]==' e')||(
$a[$i
]==' E'
))
$ev ++;
elsei f
(($a[ $i
]=='i'
)||
(
$a[$i
]=='I
')
)
$iv++;
else
i
f(
($a[$i
]=='o')||($a[$i
]==' O'))

$ov
++;

el
sei
f(
($a[
$i]=='
u'
)||

(
$a[
$i]
=='
U'
))

$uv
++;

el
se$cnt
++;
}

echo"
<br
>Tot
al'
a':$av";
echo"
<br
>Tot
al'
e':$ev"
;
echo"
<br
>Tot
al'
i':
$iv"
;
echo"
<br
>Tot
al'
o':$ov";
echo"
<br
>Tot
al'
u':$uv";
echo"
<br
>Tot
alconsenentsar
e:$cnt
";

$tot= $av
+$ev
+$i
v+$ov
+$uv
;
retur
n$tot
;
}

$str=$_ POST['
str'
]
;
$op=$_ POST['
op']
;
$l=st r
len($st
r);
switch($op)
{
case1:echo" st
ri
ngis::$str
<br>";
$v _cnt=cnt_v
owels($str
,$l
);
echo" Tot
alvowelsare::
$v
_cnt
<br>"
;
break;
case2:echo" st
ri
ngis::$str
<br>";
$v_occ=occur _
vowels($str
,$l
);
echo" l
enghti
s: :$v_occ<br>"
;

br
eak;
}

$str1=st
rrev(
$str)
;
$a=strl
en($str
);
$f=0;
for(
$j=0;
$j<$a;
$j++)
{
i
f(
$str1[
$j]
==$st
r[
$j]
)
{
$f
=0;
}
el
se
{
$f
=1;
br
eak;
}
}
i
f(
$f ==0)
{
echo"st
ri
ngi
spal
indr
ome";
}
el
se
{
echo"st
ri
ngi
snotpal
indr
ome"
;
}
?>

Output
:-PHPCodeKai seRunKar e
St
ep1: XammpCont r
ol Panel Open
Star
t:ApacheandMy sql
st
ep2: OpenanyBr owser( eg.Chromeetc)
st
ep3:local
host/seam3sl i
p/ sl
ip1.
html
Q.2Wr i
teaPHPscr iptforthefol
lowi ng:Designaf ormto
accepttwost ri
ngsf rom theuser.Findthef i
rstoccurrenceand
thelastoccurrenceoft hesmal l
stringinthel argestr
ing.Al
so
countthet ot
al numberofoccur rencesofsmal lstr
inginthe
l
argest r
ing.Prov i
deat extboxtoacceptast ring,whi
chwi l
l
repl
acet hesmal lstri
ngint hel
argest ri
ng.(Usebui l
t-
in
functi
ons)

Ans:
-

sl
ip2.
html

<ht
ml>

<body
>

<f
orm act
ion="
rsl
i
p2.
php"met
hod="
get
">

<cent
er>
<t
abl
e>

<tr
><t
d>Enter1stStr
ing:
</t
d><t
d><i
nputt
ype="
text
"
name="st
r1"></
td><t
r>

<tr
><t
d>Enter2ndStri
ng:</
td><t
d><i
nputt
ype="
text
"
name="st
r2"></
td></
tr>

<tr
><t
d>EnterStr
ingToRepl
ace:
</t
d><t
d><i
nputt
ype="
tex
t"
name="st
r3"></
td></
tr>

<tr
><t
d>Occurance</
td><t
d><i
nputt
ype="
radi
o"name="
ch"
val
ue=1></
td></t
r>

<tr
><t
d>Replace</t
d><t
d><i
nputt
ype="
radi
o"name="
ch"
val
ue=2></
td></tr
>

<t
r><t
d></
td><t
d><i
nputt
ype="
submi
t"v
alue=Next
></
td></
tr>

</
tabl
e>

</
cent
er>

</
for
m>

</
body
>

</
html
>

r
sli
p.php

<?
php

$st
r1=$_
GET[
'
str
1']
;

$st
r2=$_
GET[
'
str
2']
;

$st
r3=$_
GET[
'
str
3']
;

$ch=$_
GET[
'
ch'
]
;
echo"
Fir
stSt
ri
ngi
s=$st
r1.
<br
><br
>";

echo"
secondSt
ri
ngi
s="
.$st
r2.
"<br
><br
>";

echo"
Str
ingf
orRepl
acei
s="
.$st
r3.
"<br
><br
>";

I
f(
str
len(
$st
r1)
>st
rl
en(
$st
r2)
)

swi
tch(
$ch)

case1:
$pos=st
rpos(
$st
r1,
$st
r2)
;

i
f(
$pos!
=0)

echo"
str
ing'
$st
r2'
Notpr
esentat
t
hest
artof'
$st
r1'
.
<br
>";

el
seecho"
str
ing'
$st
r2'
presentat
t
hest
artof'
$st
r1'
.
<br
>";

br
eak;

case2:
$st
r4=st
r_r
epl
ace(
$st
r2,
$st
r3,
$st
r1)
;

echo"
Aft
err
epl
aci
ngst
ri
ng$st
r4"
;

br
eak;

}
}

el
se

swi
tch(
$ch)

case1:
$pos=st
rpos(
$st
r2,
$st
r1)
;

i
f(
$pos!
=0)

echo"
str
ing'
$st
r1'
Notpr
esentat
t
hest
artof'
$st
r2'
.
<br
>";

el
seecho"
str
ing'
$st
r1'
presentat
t
hest
artof'
$st
r2'
.
<br
>";

br
eak;

case2:
$st
r4=st
r_r
epl
ace(
$st
r1,
$st
r3,
$st
r2)
;

echo"
Aft
err
epl
aci
ngst
ri
ng$st
r4"
;

br
eak;

?
>

Q.3:-Wr
iteaPHPscr iptf
orthefoll
owing:Designafor
mt o
accepttwonumber sfrom t
heuser.Giveopti
onstochoosethe
ari
thmeticoperat
ion(useradi
obuttons).Di
splayt
heresul
ton
thenextform.(Usetheconceptoffuncti
onanddefault
parameters.Use‘i
ncl
ude’constr
uctorrequir
estmt).

Ans:
-
sl
i
p3.
html

<ht
ml>

<body
>

<FORM ACTI
ON="
rsl
i
p3.
php"met
hod="
GET"
>

<t
abl
e>

<tr
><t
d><h3>Enterfi
rstno:</t
d><t
d><i
nputt
ype=t
ext
name=no1 ></h3></td></
tr>

<tr
><t
d><h3>Entersecondno:
</t
d><t
d><i
nputt
ype=t
ext
name=no2></h3></t
d></t
r>

<tr
><td><b>SelectOper
ati
onwhi
chuhav
etoper
for
m
:</b></t
d></tr
>

<tr
><td><inputtype=r
adi
oval
ue="
1"
name=cal>Addit
ion</td></t
r>

<tr><t
d><i
nputty
pe=radi
oval
ue="
2"
name=cal>Substr
acti
on</
td></t
r>

<tr
><t
d><i
nputtype=r
adioval
ue="
3"
name=cal>Mul
ti
pli
cat
ion</t
d></t
r>

<tr
><td><i
nputt
ype=radi
oval
ue="
4"
name=cal>Di
vi
sion</t
d></t
r>

<tr
><t
d></
td><td><i
nputt
ype=submi
tname=submi
t
val
ue=Cal
cul
ate></t
d></t
r>

</
tabl
e>

</
for
m>

</
body
>

</
html
>
r
sli
p.php

<?
php

$no1=$_
GET[
'
no1'
]
;

$no2=$_
GET[
'
no2'
]
;

$cal
=$_
GET[
'
cal
'
];

i
f(
$cal
==1)

$add=$no1+$no2;

echo"
<h1>addi
ti
on="
.$add.
"</
h1>"
;

el
sei
f(
$cal
==2)

$sub=$no1-
$no2;

echo"
<h1>subt
ract
ion="
.$sub.
"</
h1>"
;

el
sei
f(
$cal
==3)

$mul
t=$no1*
$no2;

echo"
<h1>mul
ti
pli
cat
ion="
.$mul
t.
"</
h1>"
;
}

el
sei
f(
$cal
==4)

$di
v=$no1/
$no2;

echo"
<h1>di
vi
si
on="
.$di
v.
"</
h1>"
;

?
>

Q.4Wr i
teaPHPscr iptforthef oll
owi ng:Desi gnaf ormt o
accepttwostri
ngsf r
om theuser .Findwhet herthesmal l
str
ingappearsatthestartoft hel argestring.Pr ovideatext
boxtoacceptthest r
ingthatwi llreplaceal loccurrencesof
smallstr
ingpresentinthelargest r
ing.Alsospl itthelar
ge
str
ingint
osepar at
ewor ds.(User egularexpr essions)

Ans:
-

sl
i
p4.
html

<ht
ml>

<body
>

<f
orm act
ion='
sl
ip4.
php'
met
hod=post
>

<pr
e>

Ent
erf
ir
stst
ri
ng :
<i
nputt
ype='
tex
t'name='
str
1'><br
>

Ent
ersecondst
ri
ng :
<i
nputt
ype='
t
ext
'name='
str
2'><br
>
Ent
erst
ri
ngf orr
epl
ace:
<i
nputt
ype='
text
'
name='
str
3'><br
></
h2>

<i
nputt
ype='
radi
o'name="
ch"v
alue=1>Occur
ence.

<i
nputt
ype='
radi
o'name="
ch"v
alue=2>Repl
ace.

<i
nputtype='
radi
o'name="
ch"v
alue=3>spl
it
<input
t
ype=submi
tvalue=ok>

<i
nputt
ype=r
esetv
alue=cancel
>

</
pre>

</
for
m>

</
body
>

</
html
>

sl
ip4.
php

<?
php

$st
r1=$_
POST[
'
str
1']
;

$st
r2=$_
POST[
'
str
2']
;

$st
r3=$_
POST[
'
str
3']
;

$ch=$_
POST[
'
ch'
]
;
echo"
Fir
stst
ri
ng=$st
r1.
<br
>";

echo"
SecondSt
ri
ng=$st
r2.
<br
>";

echo"
Str
ingf
orr
epl
ace=$st
r3.
<br
>";

i
f(
str
len(
$st
r1)
>st
rl
en(
$st
r2)
)

swi
tch(
$ch)

case1:
$pos=st
rpos(
$st
r1,
$st
r2)
;

i
f(
$pos!
=0)

echo"
Str
ing'
$st
r2'
Notpr
esentatt
hest
artof
'
$st
r1'
.
<br
>";

el
se

echo"
Str
ing'
$st
r2'
Presentatt
hest
ratof
'
$st
r1'
.
<br
>";

br
eak;

case2:

$st
r4=st
r_r
epl
ace(
$st
r2,
$st
r3,
$st
r1)
;

pr
int
f("
\nAf
terr
epl
aci
ngst
ri
ng:
:
");

echo$st
r4;

br
eak;
case3:
$s=pr
eg_
spl
i
t("
//"
,$st
r1)
;

f
oreach(
$sas$v
)echo"
\t$v<br
>";

br
eak;

el
se

swi
tch(
$ch)

case1:
$pos=st
rpos(
$st
r2,
$st
r1)
;

i
f(
$pos!
=0)

echo"
Str
ing'
$st
r1'
Notpr
esentatt
hest
artof
'
$st
r2'
.
<br
>";

el
se

echo"
Str
ing'
$st
r1'
Presentatt
hest
artof
'
$st
r2'
.
<br
>";

br
eak;

case2:
$st
r4=st
r_r
epl
ace(
$st
r1,
$st
r3,
$st
r2)
;

echo"
Aft
err
epl
aci
ngst
ri
ng:
:
$st
r4<br
>";

br
eak;

case3:

echo"
Aft
erspl
i
tti
ngt
hest
ri
ng:
:
<br
>";
$s=pr
eg_
spl
i
t("
//"
,$st
r2)
;

f
oreach(
$sas$v
)echo"
\t$v<br
>";

?
>

Q.5Wr i
teaPHPscr iptforthef ol
lowing:Designaf ormto
acceptt
hedetail
sof5di fferentit
ems, suchasi t
em code,it
em
name,unit
ssold,r
ate.Displayt hebil
linthetabularfor
mat.
Useonly4textboxes.(Hint: Useofexplodef uncti
on.)

Ans:

sl
i
p5.
html

<ht
ml>

<head>

<st
yle>

t
abl
e{

bor
der
-col
l
apse:
col
l
apse;

t
abl
e,t
h,t
d{

bor
der
:1pxsol
i
dbl
ue;

}
</
sty
le>

</
head>

<body
>

<f
orm met
hod="
post
"act
ion="
progr
am5.
php"
>

<cent
er><h1>Ent
erdet
ail
sof5I
tems</
h1>

<h3>item code <i


nputtype="
text
"name="i
temcode"
placeholder="
ex11,12,
13,14,
15"/></
h3>

<h3>i
tem name<i
nputt
ype="
text
"name="
it
emname"/
></
h3>

<h3>uni
tssol
d<i
nputt
ype="
tex
t"name="
uni
tssol
d"/
></
h3>

<h3>r
ate <i
nputt
ype="
text
"name="
rat
e"/
></
h3>

<i
nputt
ype="
submi
t"v
alue="
Submi
t"
/>

</
cent
er>

</
for
m>

</
body
>

</
html
>

pr
ogr
am5.
php

<?
php

$i
temcode=$_
POST[
'
itemcode'
]
;

$i
temname=$_
POST[
'
itemname'
]
;

$uni
tssol
d=$_
POST[
'
uni
tssol
d'
];

$r
ate=$_
POST[
'
rat
e']
;
$i
_code=expl
ode(
',
'
,$i
temcode)
;

$i
_name=expl
ode(
',
'
,$i
temname)
;

$i
_uni
t=expl
ode(
',
'
,$uni
tssol
d);

$i
_rat
e=expl
ode(
',
'
,$r
ate)
;

$t
_amt=
((
$i_
unit
[0]
*$i
_rat
e[0]
)+(
$i_uni
t[
1]*
$i_r
ate[
1])
+($i
_uni
t[
2]*
$i_
rat
e[
2]
)+($i
_uni
t[
3]*
$i_r
ate[
3])
+($i_
unit
[4]
*$i
_rat
e[4]
))
;

echo"
<tabl
eal
i
gn=cent
erbor
der
=1>"
;

echo"<tr
><td><b>I
tem Code</
b></t
d><t
d><b>I
tem
Name</b></td><td><b>Uni
tsSold</
b></t
d><t
d><b>Rat
e
</
b></t
d></tr
>";

echo
"<t
r><td>"
.$i
_code[0].
"</
td><t
d>"
.$i_
name[
0].
"</
td><t
d>"
.$i
_uni
t[
0].
"</t
d><td>"
.$i
_rate[
0].
"</t
d></
tr>"
;

echo
"<t
r><td>"
.$i
_code[1].
"</
td><t
d>"
.$i_
name[
1].
"</
td><t
d>"
.$i
_uni
t[
1].
"</t
d><td>"
.$i
_rate[
1].
"</t
d></
tr>"
;

echo
"<t
r><td>"
.$i
_code[2].
"</
td><t
d>"
.$i_
name[
2].
"</
td><t
d>"
.$i
_uni
t[
2].
"</t
d><td>"
.$i
_rate[
2].
"</t
d></
tr>"
;

echo
"<t
r><td>"
.$i
_code[3].
"</
td><t
d>"
.$i_
name[
3].
"</
td><t
d>"
.$i
_uni
t[
3].
"</t
d><td>"
.$i
_rate[
3].
"</t
d></
tr>"
;

echo
"<t
r><td>"
.$i
_code[4].
"</
td><t
d>"
.$i_
name[
4].
"</
td><t
d>"
.$i
_uni
t[
4].
"</t
d><td>"
.$i
_rate[
4].
"</t
d></
tr>"
;
echo"
<tr
><t
hcol
span=4></
th></
tr>"
;

echo"<t
r><t
hcolspan=3>Tot
alamount
</
th><t
d>".$t
_amt.
"</
td></t
r>"
;

echo"
</t
abl
e>"
;

?
>

Q.6Wr i
teaPHPscr i
ptf ort
hefollowing:Designaformto
acceptt wost r
ings.Compar ethet wostri
ngsusingboth
met hods( ==oper ator&str
cmpf unction).Appendsecond
stri
ngt othef i
rststr
ing.Accepttheposi t
ionfrom t
heuser;
from wher ethecharactersfrom thefir
ststri
ngarerever
sed.
(User adiobuttons)

Ans:

sl
i
p6.
html

<ht
ml>

<head><t
it
le> .
html
</t
it
le></
head>

<bodybgcol
or="
viol
et">

<f
orm act
ion="
sli
p6.
php"met
hod="
post
">

<pr
e>

Ent
erf
ir
stst
ri
ng:
:
<inputt
ype="
text
"name="
str
1">

Ent
ersecondst
ri
ng:
:
<inputt
ype="
text
"name="
str
2">
Ent
erposi
ti
on:
:
<inputt
ype='
tex
t'name="
pos"
>

<i
nputt
ype="
radi
o"name="
ch"v
alue=1>compar
e

<i
nputt
ype="
radi
o"name="
ch"v
alue=2>wi
th
dat
aty
pe

<i
nputt
ype="
radi
o"name="
ch"v
alue=3>append.

<i
nputt
ype="
radi
o"name="
ch"v
alue=4>possi
ti
on
f
orr
ever
se.

<i
nputtype="
submi
t"v
alue="
check"
> <i
nput
t
ype="
reset
"val
ue="cancel
">

</
pre>

</
for
m>

</
body
>
</
html
>

sl
ip6.
php

<?
php

$st
r1=$_
POST[
'
str
1']
;

$st
r2=$_
POST[
'
str
2']
;

$pos=$_
POST[
'
pos'
]
;

$ch=$_
POST[
'
ch'
]
;

echo"
Fir
stst
ri
ng :
:$st
r1.
<br
><br
>";

echo"
Secondst
ri
ng:
:
$st
r2.
<br
><br
>";

echo"
posi
ti
onf
orr
ever
se:
:
$pos.
<br
><br
>";

echo"
choi
cei
s::
$ch.
<br
><br
>";

swi
tch(
$ch)
{

case1:

i
f(
$st
r1==$st
r2)

echo"
Bot
hst
ri
ngar
eequal
.
<br
>";

el
se

echo"
Bot
hst
ri
ngar
enotequal
.<br
>";

br
eak;

case2:

i
f(
$st
r1===$st
r2)

echo"
Bot
har
eex
atequal
.<BR>"
;

el
se

echo"
Bot
har
enotequal
.<BR>"
;

br
eak;

case3:

echo"
Aft
erappendi
ng:
:
";

echo"
$st
r1"
."
$st
r2"
;

echo"
<br
>";

br
eak;

case4:
$len=st
rl
en(
$st
r1)
-$pos;

$s=subst
r($st
r1,
$pos,
$l
en)
;

$st
r4=st
rrev
($s)
;
echo"
Aft
err
ever
se:
:
$st
r4.
<br
>";

br
eak;

?
>

Q.7Wri
teamenudri
venPHPprogr
am toper
for
mthe
f
oll
owi
ngoper
ati
onsonanassoci
ati
vearr
ay:

i
.Di
spl
ayt
heel
ement
sofanar
rayal
ongwi
tht
hekey
s.

i
i
.Di
spl
ayt
hesi
zeofanar
ray

i
i
i.Del
eteanel
ementf
rom anar
rayf
rom t
hegi
veni
ndex.

i
v.Rev
ersetheorderofeachel
ement
’skey
-val
uepai
r.
[Hi
nt:
usear
ray_
fli
p()
]

v.Tr
aver
setheel
ement
sinanar
rayi
nrandom or
der[
[Hi
nt:
useshuf
fl
e()
].

Ans:
-

sl
i
p7.
html

<ht
ml>

<f
orm act
ion='
sl
ip7.
php'
met
hod='
post
'
>

<pr
e> <h3>OPERATI
ONSOn
Arr
ay</
h3>

1<i
nputt
ype='
radi
o'name='
a'v
alue='
1'
>Di
spl
ay.
<br
>

2<i
nputt
ype='
radi
o'name='
a'v
alue='
2'
>si
ze.
<br
>

3<i
nputt
ype='
radi
o'name='
a'v
alue='
3'
>del
ete.
<br
>
4<i
nputt
ype='
radi
o'name='
a'v
alue='
4'
>rev
erse.
<br
>

5<i
nputt
ype='
radi
o'name='
a'v
alue='
5'
>tr
aver
se.
<br
>

<inputtype='submi
t'
val
ue='
ok'
> <i
nputt
ype='
reset
'
v
alue='cancel
'><br>

</
pre>

</
for
m>

</
body
>

</
html
>

sl
ip7.
php

<?
php

$arr
ay=ar
ray
('
zer
o'=>0,
'
one'
=>1,
'
two'
=>2,
'
thr
ee'
=>3,
'
four
'=>4,
'
fi
ve'
=>5);

$ch=$_
POST[
'
a']
;

swi
tch(
$ch)

case1:
for
each(
$ar
rayas$key
=>$v
alue)

echo"
key
:$key v
al:
$val
ue.
<br
>";

}
break;

case2:
echosi
zeof
($ar
ray
);

br
eak;
case3:

$l
en=si
zeof
($ar
ray
);

ar
ray
_spl
i
ce(
$ar
ray
,$l
en)
;

pr
int
_r($ar
ray
);

br
eak;

case4:

pr
int
_r(
arr
ay_
fli
p($ar
ray
));

br
eak;

case5:

shuf
fl
e($ar
ray
);

pr
int
_r(
$ar
ray
);

br
eak;

?
>

Q.8Wri
teamenudri
venPHPpr ogr
am toper
for
mthe
f
oll
owingoper
ati
onsonassoci
ati
vearr
ays:

a)Sortthearr
aybyval
ues(
changi
ngt
hekey
s)i
nascendi
ng,
descendingorder
.

b)Al
sosor
tthear
raybyv
alueswi
thoutchangi
ngt
hekey
s.

c)Fi
lt
ert
heoddel
ement
sfr
om anar
ray
.

d)Sor
tthedi
ff
erentar
ray
satagl
anceusi
ngsi
ngl
efunct
ion.
e)Mer
get
hegi
venar
ray
s.

f
)Fi
ndt
heUni
on,
int
ersect
ion&setdi
ff
erenceoft
woar
ray
s.

Ans:

sl
i
p8.
html

<ht
ml>

<bodybgcol
or="
pink"
>

<f
orm act
ion="
sli
p8.
php"met
hod="
post
">

<h2>Ent
erchoi
ce:
</h2>

<i
nputtype="r
adio"name="ch"val
ue=1>Sor
tar
raybyv
aluesi
n
ascendi
ng,descendi
ngorder<br
>

<i
nputty
pe="radi
o"name="ch"v
alue=2>Sor
tar
raybyv
alues
wi
thoutchangingkeyval
ues<br>

<i
nputt
ype="r
adio"name="
ch"v
alue=3>Fi
l
teroddel
ement
s
fr
om ar
ray<br>

<i
nputt
ype="
radi
o"name="ch"val
ue=4>Sor
tdi
ff
erentar
rayat
gl
anceusi
ngsingl
efunct
ion<br
>

<i
nputt
ype="
radi
o"name="
ch"v
alue=5>Mer
gegi
vent
woar
ray
s
<br
>

<inputtype="
radi
o"name="
ch"v
alue=6>Fi
ndi
nter
sect
ionof
twoar r
ay<br>

<i
nputt
ype="
radi
o"name="
ch"v
alue=7>Fi
nduni
onoft
woar
ray
<br
>

<inputtype="
radi
o"name="
ch"v
alue=8>Fi
ndsetdi
ff
erenceof
twoar r
ay<br>

<br
>
<i
nputt
ype="
submi
t"v
alue="
SUBMI
T"><i
nputt
ype="
reset
"
val
ue="
CLEAR">

</
body
>

</
html
>

<ht
ml>

<bodybgcol
or="
gol
d">

sl
i
p8.
php

<?
php

f
unct
ioni
s_odd(
$var
)

i
f(
$var
%2==1)

r
etur
n$v
ar;

$choi
ce=$_
POST[
'
ch'
]
;

$ar
r=ar
ray
('
a'
=>1,
'
b'=>2,
'
c'=>3,
'
d'=>4,
'
e'=>5,
'
f'
=>6,
'
g'=>7,
'
h'=>8)
;

$arr1=ar
ray
('
l'
=>11,
'
m'=>22,
'
n'=>33,
'
o'=>44,
'
p'=>55,
'
q'=>66,
'
r'
=>77,
'
s'=>88);
$arr2=ar
ray
('
a'
=>10,
'
b'=>20,
'
c'=>30,
'
d'=>40,
'
e'=>50,
'
f'
=>60,
'
g'=>70,
'
h'=>80);

swi
tch(
$choi
ce)

case1:

sor
t($ar
r);

echo"
Arr
ayi
nascendi
ngor
der
:<br
>";

pr
int
_r(
$ar
r);

r
sor
t($ar
r);

echo"
<br
>Ar
rayi
ndescendi
ngor
der
:<br
>";

pr
int
_r(
$ar
r);

br
eak;

case2:

asor
t($ar
r);

echo"
Arr
ayi
nascendi
ngor
der
:<br
>";

pr
int
_r(
$ar
r);

ar
sor
t($ar
r);

echo"
<br
>Ar
rayi
ndescendi
ngor
der
:<br
>";

pr
int
_r(
$ar
r);
br
eak;

case3:

pr
int
_r(
arr
ay_
fil
ter
($ar
r,
'i
s_odd'
))
;

br
eak;

case4:

ar
ray
_mul
ti
sor
t($ar
r,
0,
$ar
r1,
1,
$ar
r2,
0);

pr
int
_r(
$ar
r);

echo"
<br
>";

pr
int
_r(
$ar
r1)
;

echo"
<br
>";

pr
int
_r(
$ar
r2)
;

echo"
<br
>";

br
eak;

case5:

pr
int
_r(
arr
ay_
mer
ge(
$ar
r,
$ar
r1)
);

br
eak;

case6:

pr
int
_r(
arr
ay_
int
ersect
($ar
r,
$ar
r1)
);

br
eak;

case7:

$uni
on=ar
ray
_mer
ge(
$ar
r,
$ar
r1)
;
pr
int
_r(
arr
ay_
uni
que(
$uni
on)
);

br
eak;

case8:

pr
int
_r(
arr
ay_
dif
f($ar
r,
$ar
r1)
);

br
eak;

echo"
<br
><ahr
ef='
sl
ip8.
html
'
>RETURN</
a>"
;

?
>

</
font
>

</
body
>

</
html
>

Q.9Wr it
ePHPscriptt
odefi
neaninter
facewhichhas
methodsarea(
),v
olume()
.Defi
neconstantPI
.Creat
eaclass
cyl
inderwhi
chimplement
sthisi
nter
faceandcalcul
atear
ea
andv ol
ume.

Ans:

sl
i
p9.
html

<ht
ml>

<body
>

<cent
er>

<h2>Cal
cul
atear
eaandv
alueofcy
li
nder
</h2>
<f
orm act
ion="
sli
p9.
php"met
hod="
GET"
>

<h3> Ent
err
adi
us:
<inputt
ype=t
extname=r
><br
></
h3>

<h3> Ent
erhei
ght:
<inputt
ype=t
extname=h><br
><br
></
h3>

<i
nputt
ype=submi
tval
ue=submi
tname=Show>

<i
nputt
ype=r
esetv
alue=Resetname=Reset
>

</
for
m>

</
cent
er>

</
body
>

<ht
ml>

sl
ip9.
php

<?
php

$r = $_
GET[
'
r'
];

$h = $_
GET[
'
h']
;

def
ine(
'PI
'
,'
3.
14'
);

i
nter
facecal

f
unct
ionar
ea(
$r,
$h)
;

f
unct
ionv
ol(
$r,
$h)
;

}
cl
asscy
li
nderi
mpl
ement
scal

f
unct
ionar
ea(
$r,
$h)

$ar
ea = 2*
PI*
$r*
($r
+$h)
;

echo"
<h3>Thear
eaofcy
li
nderi
s
:
$ar
ea</
h3>"
;

f
unct
ionv
ol(
$r,
$h)

$v
ol= PI
*$r
*$r
*$h;

echo"
<h3>Thev
olumeofcy
li
nderi
s
:
$vol
</h3>"
;

$c = newcy
li
nder
;

$c-
>ar
ea(
$r,
$h)
;

$c-
>vol
($r
,$h)
;

?
>

Q.10Wr i
teclassdecl
arat
ionsandmemberf uncti
on
defi
nit
ionsforanemployee(code,name,designati
on)
.Design
deri
vedclassesasemp_ account(
account_
no, j
oini
ng_dat
e)
fr
om employeeandemp_sal
(basi
c_pay,ear
nings,deducti
on)
fr
om emp_account
.Wri
teamenudr ivenPHPpr ogram a)to
buil
damast ert
abl
eb)tosor
tallentr
iesc)tosearchanent r
y
d)Displ
aysalar
y

Ans:
-

sl
i
p10.
html

<!
DOCTYPEht
ml>

<ht
mll
ang="
en"di
r="
lt
r"
>

<head>

<met
achar
set
="ut
f-
8">

<t
it
le></
ti
tl
e>

</
head>

<body
>

<f
orm cl
ass="
"act
ion="
sli
p10.
php"met
hod="
post
">

<i
nputty
pe="r
adi
o"name="
rad"v
alue="
1">Bui
l
daMast
er
Table<br
><br>

<inputt
ype="
radi
o"name="
rad"v
alue="
2">Sor
tal
lent
ri
es
<br
><br>

<i
nputt
ype="
radi
o"name="
rad"v
alue="
3">Sear
chanent
ry
byEmpl
oyee'
sName

<i
nputt
ype="
tex
t"name="
ename"
><br
><br
>

<inputt
ype="
radi
o"name="
rad"v
alue="
4">Di
spl
aySal
ary
<br
><br>

<i
nputt
ype="
submi
t"name="
sub"v
alue="
Submi
t"
>
</
for
m>

</
body
>

</
html
>

sl
ip10.
php

<?
php

cl
assempl
oyee

publ
i
c$code,
$name,
$desi
g;

f
unct
ion_
_const
ruct
($a,
$b,
$c)

$t
his-
>code=$a;

$t
his-
>name=$b;

$t
his-
>desi
g=$c;

publ
i
cfunct
iondi
spl
ay_
emp(
)

echo'

<t
d>'
.
$thi
s->code.
'
</t
d>
<t
d>'
.
$thi
s->name.
'
</t
d>

<t
d>'
.
$thi
s->desi
g.'
</t
d>

'
;

publ
i
cfunct
ionget
name(
)

r
etur
n$t
his-
>name;

cl
assemp_
accext
endsempl
oyee

publ
i
c$ano,
$jdat
e;

f
unct
ion_
_const
ruct
($a,
$b,
$c,
$d,
$e)

par
ent
::
__const
ruct
($a,
$b,
$c)
;

$t
his-
>ano=$d;

$t
his-
>jdat
e=$e;

publ
i
cfunct
iondi
spl
ay_
acc(
)

{
echo'

<t
d>'
.
$thi
s->ano.
'
</t
d>

<t
d>'
.
$thi
s->j
dat
e.'
</t
d>

'
;

cl
assemp_
sal
ext
endsemp_
acc

publ
i
c$bpay
,$ear
ns,
$ded,
$tot
al;

f
unct
ion_
_const
ruct
($a,
$b,
$c,
$d,
$e,
$f,
$g,
$h)

par
ent
::
__const
ruct
($a,
$b,
$c,
$d,
$e)
;

$t
his-
>bpay
=$f
;

$t
his-
>ear
ns=$g;

$t
his-
>ded=$h;

$t
his-
>tot
al=$t
his-
>bpay+$t
his-
>ear
ns-$t
his-
>ded;

publ
i
cfunct
iondi
spl
ay_
sal
()

echo'
<t
d>'
.
$thi
s->bpay
.'
</t
d>

<t
d>'
.
$thi
s->ear
ns.
'
</t
d>

<t
d>'
.
$thi
s->ded.
'
</t
d>

<t
d>'
.
$thi
s->t
otal
.'
</t
d>

'
;

$emp[0]=new
emp_sal('
A923B'
,
'Rav
indr
a',
'
Staf
f'
,'
10001'
,
'21/
09/
2011'
,
'20000'
,
'5
000'
,
'3000')
;

$emp[1]
=new
emp_sal
('
A823B'
,
'Ki
ran'
,
'HR'
,
'10002'
,
'22/
09/
2011'
,
'25000'
,
'5000'
,
'
3000'
);

$emp[2]=new
emp_sal('
A723B'
,
'Sudhi
r'
,
'Anal
yst
',
'
10003'
,
'23/
09/
2011'
,
'22000'
,
'5
000'
,
'3000')
;

$emp[3]
=new
emp_sal
('A623B',
'
Mahesh'
,
'Or
gani
ser
',
'
10004'
,
'24/
09/
2011'
,
'2100
0'
,'
5000'
,
'3000')
;

$emp[4]
=new
emp_sal
('
A523B'
,
'Ak'
,
'Manager
',
'
10005'
,
'25/
09/
2011'
,
'30000'
,
'500
0'
,'
3000'
);

$emp[
5]=new
emp_sal
('
A423B'
,
'Rav
i'
,'
Staf
f'
,'
10006'
,
'26/
09/
2011'
,
'20000'
,
'5000'
,
'
3000'
);

$emp[6]=new
emp_sal('
A323B'
,
'Vashal
i
',
'Anal
yst
'
,'
10007'
,
'27/
09/
2011'
,
'21000'
,
'
5000'
,
'3000')
;

$emp[7]=new
emp_sal('
A223B'
,
'Mahi
'
,'
Organi
ser
',
'
10008'
,
'28/
09/
2011'
,
'21000'
,
'
5000'
,
'3000')
;

$emp[8]
=new
emp_sal
('
A123B'
,
'Kar
na'
,
'St
aff
',
'
10009'
,
'29/
09/
2011'
,
'20000'
,
'500
0'
,'
3000'
);

$emp[9]
=new
emp_sal
('
A023B'
,
'Sur
aj'
,
'St
aff
',
'
10010'
,
'30/
09/
2011'
,
'20000'
,
'5000'
,
'
3000'
);

$ch=$_
POST[
'
rad'
]
;

$ename=$_
POST[
'
ename'
]
;

$f
lag=0;

f
unct
ionmast
ert
abl
e($emp)

echo'
<tabl
ebor
der
="1"wi
dth="
100%"
>

<t
r>

<t
h>Code</
th>

<t
h>Name</
th>
<t
h>Desi
gnat
ion</
th>

<t
h>AcNo</
th>

<t
h>Joi
ndat
e</
th>

<t
h>Basi
cPay
</t
h>

<t
h>Ear
nings</
th>

<t
h>Deduct
ion</
th>

<t
h>Tot
alSal
ary
</t
h>

</
tr>'
;

f
or(
$i=0;
$i<10;
$i++)

echo'
<tr
>';

$emp[
$i]
->di
spl
ay_
emp(
);

$emp[
$i]
->di
spl
ay_
acc(
);

$emp[
$i]
->di
spl
ay_
sal
()
;

echo'
</t
r>'
;

echo'
</t
abl
e>'
;

swi
tch(
$ch)
{

case1:

mast
ert
abl
e($emp)
;

br
eak;

case2:
echo'
Sor
ti
ngw.
r.
tEmpl
oyeeCode<br
><br
>';

f
unct
ionsr
t($a,
$b)

r
etur
nst
rcmp(
$a-
>code,
$b-
>code)
;

usor
t($emp,
"sr
t"
);

mast
ert
abl
e($emp)
;

br
eak;

case3:
echo"
Sear
chi
ngf
orempl
oyee$ename.
..
..
<br
><br
>";

f
or(
$i=0;
$i<10;
$i++)

$t
emp=$emp[
$i]
->get
name(
);

i
f(
$temp==$ename)

{
$f
lag=1;

br
eak;

i
f(
$fl
ag==0)

echo"
NotFound<br
>";

el
se

echo"
Foundi
nther
ecor
ds<br
>";

br
eak;

case4:
echo"
Displ
ayi
ngSal
aryofal
lEmpl
oyees.
..
.<br
><br
>";

echo'
<tabl
ebor
der
="1"wi
dth="
100%"
>

<t
r>

<t
h>Empl
oyeeName</
th>

<t
h>Basi
cPay
</t
h>

<t
h>Ear
nings</
th>
<t
h>Deduct
ion</
th>

<t
h>Tot
alSal
ary
</t
h>

</
tr>'
;

f
or(
$i=0;
$i<10;
$i++)

echo'
<tr
>

<t
d>'
.
$emp[
$i]
->get
name(
).
'</
td>

'
;

$emp[
$i]
->di
spl
ay_
sal
()
;

br
eak;

?
>

Q.11Der iveaclasssquarefrom classRect angle.Createone


mor eclasscircl
e.Creat
eani nterfacewi t
honl yonemet hod
calledarea()
.Implementthisinterfaceinalltheclasses.
Includeappropriat
edatamember sandconst ruct
orsinall
classes.Wr i
teaPHPpr ogram toacceptdet ail
sofasquar e,
circleandrectangl
eanddi spl
ayt hear ea.
Ans:

sl
i
p11.
html

<ht
ml>

<bodybgcol
or=#84E433>

<f
orm act
ion="
sli
p11.
php"met
hod="
post
">

<pr
e>

<h1>Ci
rcl
e:</
h1>

Radi
us:
<inputt
ype=t
extname=p><BR>

<h1>

squar
e:</
h1>

si
de:
<inputt
ype=t
extname=q><BR>

<h1>

Rect
angl
e:

</
h1>

l
engt
h:<i
nputt
ype=t
extname=n><BR>

Br
eadt
h:<i
nputt
ype=t
extname=m><BR>

<i
nputtype=submi
tval
ue=submi
t><i
nputt
ype="
reset
"
val
ue=cancel>
</
pre>

</
for
m>

</
body
>

</
html
>

sl
i
p11.
php

<ht
ml>

<body
>

<?
php

$p=$_
POST[
'
p']
;

$q=$_
POST[
'
q']
;

$n=$_
POST[
'
n']
;

$m=$_
POST[
'
m']
;

i
nter
faceone

f
unct
ionar
ea(
$n,
$m)
;

cl
assr
ecti
mpl
ement
sone

{
f
unct
ionar
ea(
$n,
$m)

$ar
ea=$n*
$m;

echo"
Areaofr
ect
angl
e..
..
..
:"
.$ar
ea;

echo"
<br
><BR>"
;

cl
asssquar
eext
endsr
ect

f
unct
ionar
ea(
$q,
$q1)

$ar
ea=$q*
$q1;

echo"
AreaofSquar
e..
..
..
..
.:
".
$ar
ea;

echo"
<BR><br
>";

cl
assci
rcl
e

f
unct
ionar
ea(
$p)
{

$ar
ea=0.
5*$p*
$p;

echo"
Areaofci
rcl
e..
..
..
..
.:
".
$ar
ea;

echo"
<br
><BR>"
;

$o=newr
ect
();

$o-
>ar
ea(
$n,
$m)
;

$s=newsquar
e()
;

$s-
>ar
ea(
$q,
$q)
;

$c=newci
rcl
e()
;

$c-
>ar
ea(
$p)
;

echo"
<br
>";

?
>

<ahr
ef="
sli
p11.
html
">comeback</
a><br
>

</
body
>

</
html
>

Q. 12.Wr i
tePHPScr i
pttocreat
eacl assaccount
(accno,cust_name).Derivetwoclassesfrom accountas
sav i
ng_acc(balance,min_amount)andcur r
ent_acc(
balance,
min_ amount).Displayamenua)Sav ingAccountb)Cur r
ent
AccountForeachoft hi
sdispl
ayamenuwi ththefoll
owing
options.1.Cr eat
eaccount2.Deposi t3.Withdr
awal

Ans:
sl
i
p12.
html

<!
DOCTYPEht
ml>

<ht
ml>

<body
>

<f
orm act
ion="
sli
p12.
php"met
hod="
GET"
>

Pl
easesel
ecty
ourAccount
<br/
>

<i
nputt
ype="checkbox"name="
check_
b[]
"val
ue="
sav
ing"
/
>Savi
ngAccount<br/>

<i
nputty
pe="checkbox"name="
check_
b[]
"val
ue="
cur
rent
"
/
>Cur
rentAccount<br/>

<sel
ecti
d="
sav
ing"
>

<opt
ionv
alue="
creat
e">Cr
eat
e</
opt
ion>

<opt
ionv
alue="
deposi
te"
>Deposi
t</
opt
ion>

<opt
ionv
alue="
wit
hder
w">Wi
thder
w</
opt
ion>

</
sel
ect
>

<i
nputt
ype="
submi
t"v
alue="
sumbi
t"/
>

</
for
m>

</
body
>

</
html
>

sl
ip12.
php
<!
DOCTYPEht
ml>

<ht
ml>

<body
>

<?
php

cl
assAccount{

publ
i
c$acc_
no;

publ
i
c$acc_
name;

publ
i
cfunct
ion_
_const
ruct
($acc_
name,
$acc_
no){

$t
his-
>acc_
name=$acc_
name;

$t
his-
>acc_
no=$acc_
no;

publ
i
cfunct
ioni
ntr
o(){

echo"TheAccountname{
$thi
s->acc_
name}andAccountNo
i
s{ $t
his-
>acc_
no}.
";

cl
asssav
eing_
accext
endsAccount{

publ
i
c$bl
ance;

publ
i
c$mi
n_amount
;

publ
i
cfunct
ion_
_const
ruct
($acc_
name,
$acc_
no,
$bl
ance,
$mi
n_amount
){

$t
his-
>acc_
name=$acc_
name;

$t
his-
>acc_
no=$acc_
no;

$t
his-
>bl
ance=$bl
ance;

$t
his-
>mi
n_amount=$mi
n_amount
;

publ
i
cfunct
ioni
ntr
o(){

echo"
<tabl
ebor
der
='2'
>";

echo"<t
r><t
d>AccountName</td><t
d>Account
no</
td><td>bal
ance</
td><t
d>min_
balance</t
d></t
r>"
;

echo"
<tr
><t
d>{
$thi
s->acc_
name}
</t
d>"
;

echo"
<td>{
$thi
s->acc_
no}
</t
d>";

echo"
<td>{
$thi
s->bl
ance}
</t
d>"
;

echo"
<td>{
$thi
s->mi
n_amount
}</
td></
tr>"
;

}
cl
asscur
rent
_accext
endsAccount{

publ
i
c$bl
an;

publ
i
c$mi
n_amt
;

publi
cfuncti
on__const
ruct
($acc_
name,
$acc_
no,
$blan,
$min_amount){

$t
his-
>acc_
name=$acc_
name;

$t
his-
>acc_
no=$acc_
no;

$t
his-
>bl
an=$bl
an;

$t
his-
>mi
n_amount=$mi
n_amount
;

publ
i
cfunct
ioni
ntr
o(){

echo"<t
r><t
d>{
$thi
s->acc_
name}
</t
d>"
;

echo"
<td>{
$thi
s->acc_
no}
</t
d>";

echo"
<td>{
$thi
s->bl
an}
</t
d>"
;

echo"
<td>{
$thi
s->mi
n_amount
}</
td></
tr>"
;

echo"
</t
abl
e>"
;

$sav
eing_
acc=newsav
eing_
acc(
"Rav
indr
a",
1111,
5000,
1000)
;

$sav
eing_
acc-
>int
ro(
);
$cur
rent
_acc=newcur
rent
_acc(
"Ki
ran"
,2222,
100000,
1000)
;

$cur
rent
_acc-
>int
ro(
);

?
>

</
body
>

</
html
>

Q. 13Implementcalculatortoconv ertdi
stancesbetween
(bothway s)mil
esandki lomet r
es.Onemi l
eisabout1.609
kil
omet r
es.Userinterf
ace( dist
ance.html)hasonet ext
-i
nput
,
twor adi
o-but
tons,submi tandr eset-
buttons.Val
uesar e
postedtoPHP- scri
pt(distance.php)whichcalcul
atesthe
conversi
onsaccor dingtheuseri nput.

Ans:

sl
i
p13.
html

<ht
ml>

<body
>

<cent
er>

<h2>Cal
cul
atekm andmi
l
e</
h2>

<f
orm act
ion="
sli
p13.
php"met
hod="
POST"
>

Ent
erDi
stance:
<i
nputt
ype="
tex
t"name="
dist
ance"/
><br
/>

Kms:
<i
nputt
ype="
radi
o"name="
uni
ts"v
alue="
kms"/
><br
/>

Mi
l
es:
<i
nputt
ype="
radi
o"name="
uni
ts"v
alue="
mil
es"/
>

<br
/>

<i
nputt
ype="
submi
t"v
alue="
submi
t"name="
Show"/
>
<i
nputt
ype="
reset
"val
ue="
Reset
"name="
Reset
"/>

</
for
m>

</
cent
er>

</
body
>

<ht
ml>

sl
i
p13.
php

<?
php

$di
stance=$_
POST[
'
dist
ance'
]
;

$uni
ts=$_
POST[
'
uni
ts'
]
;

i
f(
$uni
ts=='
kms'
){

$mi
l
es=$di
stance/
1.60934;

echo'
Thedi
stancei
s'
.r
ound(
$mi
l
es)
.'
mil
es.
'
;

}
else{

$kms=$di
stance*
1.60934;

echo'
Thedi
stancei
s'
.r
ound(
$kms)
.'
kms.
'
;

?
>

Q.14Usingregularexpr
essionscheckforthev
ali
dit
yof
enter
edemai l
-i
d.The@ symbol shoul
dnotappearmorethan
once.Thedot(.)canappearatthemostoncebefore@ andat
themosttwiceoratleastonceafter@ sy
mbol.Thesubstr
ing
befor
e@ shoul
dnotbeginwit
hadigi
torunder
scor
eordotor
@ oranyot
herspeci
alchar
acter
.

Ans:

sl
i
p14.
html

<ht
ml>

<body
>

<f
orm name="
for
m1"met
hod="
post
"act
ion="
sli
p14.
php"
>

Ent
ert
heEmai
l
ID*
<inputt
ype="
tex
t"name="
emai
l
"></
input
>

<i
nputt
ype="
submi
t"v
alue="
submi
t"
></
input
>

</
for
m>

</
body
>

</
html
>

sl
ip14.
php

<?
php

$emai
l
=$_
POST[
'
emai
l
']
;

$r
egex='/^[
_a-
z0-
9-]
+(\
.[
a-z
0-9-
]+)
*@[
a-z
0-9]
+(\
.[
a-z0-
9-]
+)*
(\.
[a
-
z]{
2,3}
)$/
';

i
f(
preg_
mat
ch(
$regex
,$emai
l
)){

echo$emai
l."
iti
sval
i
demai
li
d";

}
el
se

echo$emai
l.
"i
nval
i
demai
l
,Pl
easet
ryagai
n."
;

?
>

Q.15Wr i
tePHPpr ogr
am tocr
eatei
nputformf orGrocerythat
di
splaysListofgr
oceryi
temswithcheckboxesandcr eatea
bi
llaccordi
ngtoli
stofit
emsselect
edaftercli
ckingsubmi t
butt
on.

Ans:

sl
i
p15.
html

<!
DOCTYPEht
ml>

<ht
ml>

<body
>

<f
orm act
ion="
sli
p15.
php"met
hod="
GET"
>

Pl
easesel
ecty
ourgel
oser
y<br/
>

<inputt
ype="
checkbox"name="
check_
b[]
"val
ue="
ri
ce"
/
>Rice<br/
>

<i
nputtype="
checkbox"name="
check_
b[]
"val
ue="
oil
s"
/
>Oil
s<br/
>

<i
nputt
ype="
checkbox"name="
check_
b[]
"val
ue="
mil
k"
/
>Mi
l
k<br/
>

<inputt
ype="
checkbox"name="
check_
b[]
"val
ue="
bread"
/
>Bread<br/>

<i
nputt
ype="
submi
t"v
alue="
sumbi
t"/
>

</
for
m>

</
body
>

</
html
>

sl
ip15.
php

<?
php

$host
name="
127.
0.0.
1";

$db_
name="
grecer
y";

$user
name="
root
";

$passwor
d="
";

$connecti
on=mysqli
_connect
("
$host
name"
,"
$user
name"
,"
$pass
word",
"$db_name"
)or

di
e("
unabl
etoconnect
");

i
f(
!$connect
ion)
{

echo"
Err
or:
Unabl
etoconnectt
oMy
SQL.
<br
>";

echo"
<br
>Debuggi
nger
rno:
".my
sql
i
_connect
_er
rno(
);

echo"
<br
>Debuggi
nger
rno:
".my
sql
i
_connect
_er
rno(
);

exi
t;
}

i
f(
$st
mt=$connect
ion-
>quer
y("
SELECT*FROM `
bil
l̀"
)){

echo"
<tabl
ebor
der
='2'
>";

echo"<t
r><td>sr
.no</t
d><td>Name
I
tem</td><td>Qunti
ty</
td><t
d>Rate</
td><t
d>Amount
</t
d></
tr>
"
;

whi
l
e($r
ow=$st
mt-
>fet
ch_
assoc(
)){

echo"
<tr
><t
d>"
.$r
ow[
'
s.no'
]
."</
td>"
;

echo"
<td>"
.$r
ow[
'
NameI
tem'
]
."</
td>"
;

echo"
<td>"
.$r
ow[
'
Qunt
it
y'
].
"</
td>"
;

echo"
<td>"
.$r
ow[
'
Rat
e']
."
</t
d>"
;

echo"
<td>"
.$r
ow[
'
Amount
']
."
</t
d></
tr>"
;

echo"
</t
abl
e>"
;

?
>

phpmy
admi
ncr
eat
edat
abase:
st
ep1:
chr
omet
ypel
ocal
host
/phpmy
admi
n

st
ep2:cr
eat
enewdat
abase"
grecer
y"

CREATETABLE`
bil
l̀(

`
s.no`i
nt(
11)NOTNULL,

`
NameI
tem`v
archar
(11)NOTNULL,

`
Qunt
it
y`i
nt(
11)NOTNULL,

`
Rat
e`i
nt(
11)NOTNULL,

`
Amount
`int
(11)NOTNULL

)ENGI
NE=I
nnoDBDEFAULTCHARSET=ut
f8mb4;

I
NSERTI
NTO` bi
l
l̀(
`s.
no`
,`NameI
tem`
,`Qunt
it
y`,
`Rat
e`,
`
Amount
`)VALUES

(
1,'
Rice'
,670,
35,
3500)
,

(
2,'
Oil
s'
,345,
120,
12222)
;

ALTERTABLE`
bil

ADDPRI
MARYKEY(
`s.
no`
);

ALTERTABLE`
bil

MODI
FY`s.
no`i
nt(
11)NOTNULLAUTO_
INCREMENT,
AUTO_
INCREMENT=3;

COMMI
T;
Q19.Wr
it
eaPHPscr
iptt
okeept
rackofnumberoft
imest
heweb
pagehasbeenaccessed.
coo8.
html

<ht
ml>

<body
>

<f
orm met
hod=postact
ion=coo8.
php>

Ent
ername<i
nputt
ype=t
extname=nm><p>

<i
nputt
ype="
submi
t"v
alue="
cli
ckme"
>

</
for
m>

</
body
>

</
html
>

coo8.
php

<?
php

$name='
vi
sit
Count
';

i
f(
!i
sset
($_
COOKI
E[$name]
))
{

$_
COOKI
E[$name]=0;

$_
COOKI
E[$name]=1+(
int
)max(
0,$_
COOKI
E[$name]
);
$r
esul
t=set
cooki
e($name,
$_COOKI
E[$name]
);

i
f(
!$r
esul
t){

thr
ownewRuntimeEx
cepti
on(
"Fai
l
ed
t
osetcooki
e\"
$name\""
);

echo"
Hel
l
o<b>"
.$_
POST[
'
nm'
]
."</
b><br
>";

echo"<br
/>Youhaveaccessedt
hepage
<b>".
$_COOKIE[
$name].
"</b>
ti
mes<br>";

echo"
<br
/><ahr
ef='
coo8.
html
'
>coo8.
html
</a>"
;
?
>
Q.21Changet hepreferencesofyour
webpagel i
kef ontstyl
e,fontsi
ze,f
ontcol
or,
background
colorusingcooki e.
Displayselectedsetti
ngsonnextwebpageandact ual
i
mpl ementat i
on( wi
thnew
setti
ngs)ont hirdwebpage.
font.
html
<html>

<body
>

<f
orm met
hod="
post
"act
ion="
font
.php"
>

<b>Ent
erst
ri
ng:
</b><i
nputt
ype="
tex
t"
name="
str
"/></
br>

<b>Ent
erfont:
</b><i
nputty
pe="
text
"
name="font
name"/></br
>

<b>Ent
erBackgr
oundcol
or:
</b><i
nputt
ype="
text
"
name="bname"/
>

<i
nputt
ype="
submi
t"name="
submi
t"/
>

</
for
m>

</
body
>

</
html
>

f
ont
.php

<?
php

i
f(
$_POST[
'
submi
t'
]){

/
/$f
ont
Name=$_
POST[
'
font
name'
]
;

/
/$bcol
or=$_
POST[
'
bname'
]
;

/
/$_
COOKI
E['
fname'
]=
$_
POST[
'
font
name'
]
;

set
cooki
e('
bname'
,
$_POST[
'
bname'
]
);

set
cooki
e('
fname'
,
$_POST[
'
font
name'
]
);

set
cooki
e('
str
',
$_POST[
'
str
']
);

echo"<b>Ent
eredStri
ng
:
</b>"
.$_POST[
'st
r'
];

echo"</br
><b>Sel
ected
f
ont:</
b>".
$_POST['
font
name'
]
;

echo"</br
><b>Sel
ected
Backgr
oundcolor:
</b>"
.$_
POST[
'
bname'
]
;

echo"</
br><a
hr
ef='
vi
ew.php'
>Vi
ewI
mpl
ment
ati
on</
a>"
;

?>
vi
ew.php
<ht
ml>

<?
php

echo"<bodybgcol
or='
".
$_COOKIE['
bname'
]
."'
><f
ont
face='
".
$_COOKIE[
'
fname']
."
'
size='
8'
>".
$_COOKIE[
'
str
']
."
</font
>";
?>
<ht
ml>

2)Wr
it
eaPHPscri
pttoacceptan
.
XMLfil
ewhi
chshoul
dcompr i
sethef
oll
owi
ng:

<cri
cket><pl
ayer
>abc</
play
er><runs>1000</r
uns><wi
cket
s>50
</wicket
s><noof
notout
>10</noofnot
out></cr
icket
>

Foratl
east5pl
ayer
s.

Displayt
hedetai
lsof
playerswhohavescoredmor
ethan1000r
unsandatl
east50
wickets.
<?xml
versi
on='1.
0'
>

<cr
icket
inf
o>

<cr
icket
>

<pl
ayer
>abc</
play
er>

<r
uns>1000</
runs>

<wi
cket
s>50</
wicket
s>

<noof
not
out
>10</
noof
not
out
>

</
cri
cket
>
<cr
icket
>

<pl
ayer
>aaa</
play
er>

<r
uns>1000</
runs>

<wi
cket
s>40</
wicket
s>

<noof
not
out
>10</
noof
not
out
>

</
cri
cket
>

<cr
icket
>

<pl
ayer
>bbb</
play
er>

<r
uns>1000</
runs>

<wi
cket
s>40</
wicket
s>

<noof
not
out
>10</
noof
not
out
>

</
cri
cket
>

<cr
icket
>

<pl
ayer
>ccc</
play
er>

<r
uns>1000</
runs>

<wi
cket
s>40</
wicket
s>

<noof
not
out
>10</
noof
not
out
>
</
cri
cket
>

<cr
icket
>

<pl
ayer
>ddd</
play
er>

<r
uns>1000</
runs>

<wi
cket
s>40</
wicket
s>

<noof
not
out
>10</
noof
not
out
>

</
cri
cket
>

</
cri
cket
inf
o>

sl
ip20.
php

<?
php

$d=newDOMDocument
();

$d-
>load(
"sl
i
p28.
xml
")
;

$r
un=$d-
>get
Element
sBy
TagName(
'r
uns'
);

$wi
c=$d-
>get
Element
sBy
TagName(
'wi
cket
s')
;

$name=$d-
>get
Element
sBy
TagName(
'pl
ayer
')
;

f
oreach(
$nameas$n)
{

if
($r
un=='1000'
&&$wic>='50'
)

echo
"
<br>"
.$n-
>text
Cont
ent
;

else
"
not";

?
>
Q21Wr it
eaPHPscr i
pttocr eateaf or
mt oacceptstudent
i
nfor mati
on( name, class,addr ess).
Oncet hestudenti nformationi saccepted,acceptmarksinnex t
for
m( Phy,Bio,Chem,
Mat hs,Marat hi
,English)
.Displaythemar ksheetforthestudent
i
nt henex tform containingname, cl
ass,mar ksoft
hesubj ect
,
t
otal andper centage.
fir
st .
php

<ht
ml>

<body
>

<f
orm met
hod="
post
"act
ion="
second.
php"
>

<b>St
udentNo:
-</b><i
nputt
ype="
text
"
name="sno"
></
br>
<b>St
udentName:
-</b><i
nputt
ype="
text
"
name="sname"
></
br>

<b>St
udentcl
ass:-</
b><i
nputt
ype="
text
"
name="cl
ass"
></br>

<b>St
udentaddr
ess:-</
b><i
nputt
ype="
text
"
name="addr
ess"
></br>

<i
nputt
ype="
submi
t"v
alue="
sav
e">

</
for
m>

</
body
>

</
html
>

second.
php

<ht
ml>

<body
>

<?
php

/
*sessi
on_
star
t()
;

$_
SESSI
ON[
"sno"
]=$_
POST[
"sno"
];
$_
SESSI
ON[
"sname"
]=$_
POST[
"sname"
];

$_
SESSI
ON[
"scl
ass"
]=$_
POST[
"cl
ass"
];

$_
SESSI
ON[
"addr
ess"
]=$_
POST[
"addr
ess"
];
*/

set
Cooki
e('
sno'
,
$_POST[
"sno"
])
;

set
Cooki
e('
sname'
,
$_POST[
"sname"
])
;

set
Cooki
e('
cl
ass'
,
$_POST[
"cl
ass"
])
;

set
Cooki
e('
addr
ess'
,
$_POST[
"addr
ess"
])
;

echo"
Hello"
.$_
POST[
"sname"
].
"!
Ent
er
Marks.
..
.<br
>";

?
>
Q22. Wr i
teaPHPpr ogram tocreateashoppingmallUI.Usermust
beal l
owedt odopur chase
from twopages.Eachpageshoul dhaveapaget ot
al.Thethi
rd
pageshoul ddispl
aya
bill
,whichconsi st
sofapaget otalofwhat
everthepurchasehas
beendoneandpr int
thetotal.(Useht t
psessiontracking)
.

f
ir
st.
php
<ht
ml><head><tit
le>Shoppi ng
Mall
</t
it
le></head><body ><form
method="post"action=" second.php"><b>Wow
Shoppi
ng</b><table><tr><td><table><tr
><td><b>Java
Book</
b><inputtype=" radio"name=" book"
val
ue="
java"></t
d><t d><b>Pr i
ze:100</b></td></
tr><t
r><t
d><b>
CPP
Book</ b><inputtype="radi
o"name=" book"
value="cpp"></td><td><b>Pri
z e:
120</b></td></tr
><tr><td><b>I
T
Book</ b><inputtype="radi
o"name=" book"
value="i
t"></td><td><b>Pri
ze:150</b></td></t
r></table></t
d></
tr
><tr><td><input
type="submi t"name=" submit
"
value="Purchase"></ t
d></t
r></ t
abl
e></form></ body></html>
second.
php
<html><body ><? phpsessi on_ start();
if
(isset ($_ POST[ '
book']
)){if
(
$_POST[ '
book' ]==' j
av a'){$_ SESSI ON[ "bpr ize"]=100;
$_SESSI ON[ "bname" ]=$_ POST[ "book" ]
; }if($_ POST[ '
book']==
'
cpp'){$_ SESSI ON[ "bpr i
ze" ]
=120;
$_SESSI ON[ "bname" ]=$_ POST[ "book" ]
;}i f
( $_POST[ '
book'
]==
'
it'
){$_ SESSI ON[ "bpr i
ze" ]
=150;
$_SESSI ON[ "bname" ]=$_ POST[ "book" ]
;} }? ><f or m
met hod=" post "act ion=" third.php"><b>Wow
Shoppi ng
Mobi l
e</ b><t able><t r><td><t able><t r
><t d><b>Samsung
</b><inputt y pe="radi o"name=" book"
value="samsung" ></ td><t d><b>Pr ize:10000</ b></ t
d></tr
><tr><
td><b>Mi cromax</ b><i nput
type="radio"name=" book"
value="mi cromax "></ td><t d><b>Pr ize:12000</ b></td></t
r><tr>
<td><b>Appl e</b><i nput
type="radio"name=" book"
value="appl e"></td><t d><b>Pr i
ze:15000</ b></ td></tr
></t
able><
/td></tr><tr><td><b>Tot al</b></ t
d><t d><? php
echo$_ SESSI ON[ '
bpr i
ze'];
? ></td></ tr
><t r><t d><input
type="submi t"name=" submi t
"
value="Pur chase" ></ td></ tr></table></ form></ body ></ht
ml >th
i
rd.php<ht ml ><body ><? phpsessi on_st art
();
if(i
sset (
$_ POST[ '
boo
k']
)){if(
$_ POST[ '
book' ]==' samsung' ){
$_SESSI ON[ "mpr ize" ]=10000;
$_SESSI ON[ "mname" ]=$_POST[ "book" ];}if(
$_ POST[ 'book']==
'
mi cromax' ){$_ SESSI ON[ "
mpr ize" ]
=12000; $_ SESSI ON[ "mname
"]
=$_ POST[ "book" ]
;
}i f
($_POST[ '
book' ]==' appl e'){$_ SESSI ON[ "
mpr i
ze"]=15000;
$_SESSI ON[ "mname" ]=$_POST[ "book" ];}}? ><form
met hod=" post "act ion=" four th.php" ><b>Wow
Shoppi ng
Lapt op</ b><t able><t r><t d><t able><t r><td><b>Samsung
</b><inputt y pe="radi o"name=" book"
value="samsung" ></ td><t d><b>Pr i
ze:45000</ b></ td></ t
r><tr><
td><b>Lenov o</ b><i nput
type="radi o"name=" book"
value="lenov o"></ td><t d><b>Pr iz e:
35000</ b></ td></ tr
><tr><td>
<b>Appl e</ b><input
type="radi o"name=" book"
value="appl e"></td><t d><b>Pr i
ze: 60000</ b></ td></ t
r></table><
/td></tr><t r><td><b>Tot al</ b></ td><td><? php
echo
$_SESSI ON[ 'bprize']+$_ SESSI ON[ 'mpr ize']
;?></td></ tr><tr
><td><i
nput
type="submi t"
value="Pur chase" ></ td></ tr></ table></ f
orm></ body ></html>f o
urth.php<ht ml><body ><?phpsessi on_ start();
i
f(isset($_ POST['bo
ok'])
){if($_ POST[ '
book' ]==' samsung' ){
$_SESSI ON[ "lpri
z e"]=45000;
$_SESSI ON[ "lname" ]=$_ POST[ "book" ];}if($_POST[ '
book' ]==
'
lenov o'
){$_ SESSI ON[ "
lprize" ]
=35000;
$_SESSI ON[ "lname" ]=$_ POST[ "book" ];}i f(
$_ POST[ 'book']==
'
appl e'
){$_ SESSI ON[ "lprize"]=60000;
$_SESSI ON[ "lname" ]=$_ POST[ "book" ];} }?><tabl e><tr><td>Your
selectedProducts</ t
d></ t
r><tr><td><? php
echo$_ SESSION['bname' ];?></td><td><? php
echo$_ SESSION['bprize']
;?></ t
d></ t
r><t r><t d><?php
echo$_ SESSION['mname' ]
;? ></td><td><? php
echo$_ SESSION['mpr i
z e'
];?></td></tr><t r><td><?php
echo$_ SESSION['l
name' ]
;?></ t
d><td><? php
echo$_ SESSION['l
pr i
ze'];
?></ t
d></tr
><tr
><t d><b>Tot al</b></td><t d><?php
echo
$_SESSI ON['
bpri
ze']+$_SESSI ON[ '
mpr ize']+$_ SESSION['
l
pri
ze'
]
;
?></td></t
r></table></form></ body ></ html >
Q23. WriteaPHPscr i
pttocreateaformt oacceptcust
omer
i
nformation( name,address,ph-
no).Oncet hecustomerinformationi
saccepted,accept
producti
nf ormati
oninthenext
form(Productname, qty,rat
e).Displ
aythebil
lfort
hecustomer
i
nt henextf orm.Bi
ll
shouldcont ai
nthecustomeri nf
ormationandtheinfor
mation
oftheproduct senter
ed.
f
ir
st.
php

<ht
ml>

<body
>

<f
orm met
hod="
post
"act
ion="
second.
php"
>

<t
abl
ebor
der
="1"
>

<t
r>

<t
d>cust
omerName:
-</
td>
<td><i
nputt
ype="
text
"
name="name"></
td>

</
tr>

<t
r>

<t
d>cust
omerPhoneNumber
:-
</t
d>

<td><i
nputtype="
text
"
name="ph-no"></
td>

</
tr>

<t
r>

<t
d>cust
omeraddr
ess:
-</
td>

<td><i
nputt
ype="t
ext"
name="addr
ess"></t
d>

</
tr>

<t
r>

<t
d></
td>

<td><inputty
pe="submi
t"
value="save"
></
td>

</
tr>
</
tabl
e>

</
for
m>

</
body
>

</
html
>

second.
php

<ht
ml>

<body
>

<?
php

set
Cooki
e('
name'
,
$_POST[
"name"
])
;

set
Cooki
e('
ph-
no'
,
$_POST[
"ph-
no"
])
;

set
Cooki
e('
addr
ess'
,
$_POST[
"addr
ess"
])
;

echo"
Hell
o".
$_POST[
"name"
].
"!
Ent
er
Detai
l
s..
..
<br
>";

?
>

<f
orm met
hod="
post
"act
ion="
thi
rd.
php"
>

<t
abl
ebor
der
="1"
>

<tr
><t
d>Pr
oductname</t
d><t
d><i
nput
ty
pe="t
ext
"name="pname"
></t
d></
tr>
<tr
><t
d>qt
y</t
d><t
d><input
ty
pe="t
ext
"name="qt
y"></t
d></
tr>

<tr
><t
d>rate</
td><t
d><input
ty
pe="t
ext"name="rat
e"></t
d></
tr>

<tr><t
d></ t
d><td><i
nput
type="submit"name="submit
"
value="DISPLAY"></t
d></t
r>

</
tabl
e>

</
for
m>

</
body
>

</
html
>

t
hir
d.php

<ht
ml>

<body
>

<?
php

echo"
<b>cust
omerDet
ail
s</
b><br
>";

echo"
<tabl
ebor
der
='1'
>";

echo"
<tr
><t
d>"
;
echo"
cust
omer
Name:
".
$_COOKI
E["
name"
].
"<br
>";

echo"
</t
r></
td>"
;

echo"
<tr
><t
d>"
;

echo"
customer
phone:
-"
.$_COOKI
E["
ph-
no"
].
"<br
>";

echo"
</t
r></
td>"
;

echo"
<tr
><t
d>"
;

echo"Studcust
omer
ent
address:-
".
$_COOKI
E["
addr
ess"
].
"<br
>";

echo"
</t
r></
td>"
;

echo"
<tr
><t
d>"
;

echo"
<b>cust
omerBi
l
l</
b><br
>";

echo"
</t
r></
td>"
;

echo"
<tr
><t
d>"
;

echo"pname:"
.$_
REQUEST[
"pname"
];
echo
"</
tr></t
d>"
;

echo"
<tr
><t
d>"
;

echo"qt
y:"
.$_REQUEST[
"qt
y"]
;
echo
"</
tr></
td>";
echo"
<tr
><t
d>"
;

echo"rat
e:"
.$_
REQUEST[
"r
ate"
];
echo
"</
tr></t
d>";

echo"
</t
abl
e>"
;

i
f(
isset
($_
POST[
'
submi
t'
])
)

$qt
y=(
int
)$_
POST[
'
qty
']
;

$r
ate=(
int
)$_
POST[
'
rat
e']
;

$t
otal
=$qt
y*$r
ate;

echo"
Tot
al="
.$t
otal
;

?
>

</
body
>

</
html
>
Q24.Wr it
eaPHPscr iptt
oacceptuser
nameandpassword.I
f
i
nt hefi
rstthr
eechances,
usernameandpasswor dent
erediscor
rect
,thendi
spl
ay
secondform,other
wise
displ
ayerrormessage.
<?
php

/
/$_
SESSI
ON[
'
chance'
]
=''
;

sessi
on_
star
t()
;

/
/sessi
on_
regi
ster
("chance"
);

/
/sessi
on_
regi
ster
("chance"
);

/
/echo$_
SESSI
ON[
'
chance'
]
;

i
f(
$_SERVER[
'
REQUEST_
METHOD'
]
=='
GET'
)

?
>

<f
orm method="
post
"
act
ion="
<?phpecho$_SERVER[
'
PHP_
SELF'
]
?>"
>

<B>Name</b><i
nput
t
ype="t
ext
"name="fname"val
ue="
<?php
i
f(
isset
($_
POST['
fname']
))
echo $_
POST['
fname'
]
;?>"
/>

<B>password</
b><input
t
ype="pwd"name="pwd"val
ue="<?
php
i
f(
isset(
$_POST[
'pwd']
))
echo $_
POST['
pwd'
]
;?>"
/>

<i
nputtype="
submit"
name="submited"v
alue="
submi
t"
>

</
for
m>
<?
php

el
sei
f(
$_SERVER[
'
REQUEST_
METHOD'
]
=='
POST'
)

$name=$_
POST[
'
fname'
]
;

$pwd=$_
POST[
'
pwd'
]
;

if((
$name==" n"
)&&(
$pwd=="e"
))echo
"
hi<ahref
='next.
php'
>nextf
orm</a></br
>";

el
se{

$_
SESSI
ON[
'
chance'
]
++;

echo"wrongusername&
password,Chance".
$_SESSI
ON[
'
chance'
]
."gone!
!!
";

/
/$_
SESSI
ON[
'
chance'
]=$chance;

if(
$_SESSION['
chance'
]==3)
echo"<br
/>sor
ry.
..
.urchancesar
efi
nished"
;

el
se{
di
e("
notabl
e")
;

?
>
Q26.Consi derthef oll
owingent it
iesandt hei
rrel
ationshi
ps
Doctor(doc_no, doc_name,
address,cit
y,area)Hospi tal(hosp_no,hosp_name, hosp_ci
ty)
DoctorandHospi talare
rel
atedwi t
hmany -
manyr elati
onship.CreateaRDBi n3NFf or
theabov eandsol ve
fol
lowingUsingabov edatabase, writ
eaPHPscr iptwhich
acceptshospital nameand
pri
ntinformationaboutdoct orsvisi
ti
ng/wor kinginthat
hospit
al i
ntabularf ormat.
<ht
ml>

<body
>

<f
orm act
ion="
sli
p26.
php"met
hod="
get
">

Ent
erthenameofHospi
tal
name :<i
nputt
ype=t
ext
name=hname><br
>

<i
nputt
ype=submi
tval
ue=SUBMI
T>

</
for
m>

</
body
>

<ht
ml>
sl
i
p26.
php

<?
php

$dat
abase="
archana"
;//
dat
abasename

$hname=$_
GET[
'
hname'
]
;

$con=@my
sql_connect
("
local
host
",
"r
oot
","
")
;/
/for
wamp3rdfei
l
di sbal
nk

i
f(
!$con)

di
e('
Coul
dnotconnect
:'.my
sql
_er
ror
())
;

my
sql
_sel
ect
_db(
"$dat
abase"
,$con)
;

$resul
t=mysql_query(
"sel
ect*f
rom doctor
,hospi
tal
,dhwhere
doctor
.doc_no=dh.doc_noandhospi
tal
.hosp_no=dh.hos_
no
and
hosp_
name='
$hname'
"
)ordi
e(my
sql
_er
ror
())
;

echo"
<tabl
ebor
der
='1'
>";

echo"
<tr
><t
h>dno</
th><t
h>name</
th><t
h>addr
ess</
th></
tr>"
;

whi
l
e($r
ow=my
sql
_fet
ch_
arr
ay(
$resul
t)
)

echo"
<tr
><t
d>"
;

echo$r
ow[
'
doc_
no'
]
;

echo"
</t
d><t
d>"
;

echo$r
ow[
'
doc_
name'
]
;

echo"
</t
d><t
d>"
;

echo$r
ow[
'
addr
ess'
]
;

echo"
</t
d></
tr>"
;

echo"
</t
abl
e>"
;

my
sql
_cl
ose(
$con)
;

?
>
Q28.Consi derthefol
lowingentiti
esandt heirrel
ati
onships
student( snoi nt
eger,s_namechar (30),s_cl
asschar (
10),s_addr
char(50) )
,
teacher( tnointeger,t
_namechar( 20),
qualif
icati
onchar
(15),
exper ienceinteger)
.
Ther elati
onshi pbetweenst udent-
teacher:m-m wi t
hdescripti
ve
attr
ibutesubj ect.
Usingabov edat abasewriteascriptinPHPt oacceptat eacher
namef rom userand
displaythenamesofst udentsalongwi thsubjectstowhom
teacheri steaching.
<ht
ml>

<body
>

<f
orm act
ion="
s28.
php"
method="
POST">

<t
abl
ebor
der
=1>

<t
r>

<t
d>Ent
ert
eacher
'sname:
</t
d>

<td><i
nputtype="
text
"
name="tname"></
td>

</
tr>

<t
r><t
d></
td><t
d><i
nput
t
ype="submit
"name="submit
"
v
alue="Submit
"></
td></
tr>

</
for
m>

</
body
>

</
html
>

S28.
php

<?
php

$dat
abase="
archana2"
;

$con
=mysql
i
_connect
("
local
host
",
"r
oot
","
")
;

i
f(!
$con)

di
e('
Coul
dnotconnect
:'.my
sql
i
_er
ror
())
;

my
sql
i
_sel
ect
_db(
$con,
"$dat
abase"
);

$t
name=$_
POST[
'
tname'
]
;
echo$quer y="selectsname,subj
ectfrom
student
,s_t,
teacherwher estudent
.sno=s_t
.snoand
teacher
.tno=s_ t
.t
no andt name='"
.$t
name."'"
;

$r
esul
t=my
sql
i
_quer
y($con,
$quer
y);

i
f(
!$r
esul
t)

di
e("
Aner
roroccur
ed.
..
")
;

echo'
<tabl
e>

<t
r>

<t
h>Sname</
th>

<t
h>Subj
ect
</t
h>

</
tr>'
;

whi
l
e($r
ow=my
sql
i
_fet
ch_
arr
ay(
$resul
t)
)

echo'
<t
r>

<t
d>'
.
$row[
0].
'
</t
d>

<t
d>'
.
$row[
1].
'
</t
d>

</
tr>'
;

echo'
</t
abl
e>'
;

my
sql
i
_cl
ose(
$con)
;

?
>
Q30.Consi
der
ert
hef
oll
owi
ngent
it
iesandt
hei
rrel
ati
onshi
ps
Student(Stud_ i
d,name, class)
Compet it
ion(c_ no,c_name, ty
pe)
Relati
onshipbet weenst udentandcompet i
ti
onismany -manywit
h
attr
ibut
er ankand
year.CreateaRDBi n3NFf ortheabov eandsolv
et hefol
lowi
ng.
Usingabov e
databasewr it
eascr iptinPHPt oacceptacompet i
tionnamefrom
useranddi splay
i
nformat i
onofst udentwhohassecur ed1strankinthat
compet i
tion.

Sl
ip30.
html
<ht ml><body><f orm
action="
sli
p30.php"met hod="get"
>Ent
erthenameof
compet i
ti
on :<i nputtype=text
name=comname><br ><input
type=submitvalue=SUBMI T></f
orm></body
><ht
ml>
Sl
ip30.
php
<? php$dat abase=" archana2" ;
//database
name$c_ name=$_ GET[ '
comname' ]
;$con=my sqli
_connect (
"loc
alhost","
root"
,
"");
//forwamp3r df eil
di sbalnki f(!
$con){di e('
Couldnot
connect :'.
my sqli_error(
));}my sqli_sel
ect _db($con,$dat abase);
$result=my
sqli_
quer y($con,"select
*from st ud,compe, sccwher est ud.stud_id=scc. stud_i
dand
scc.c_no=compe. c_ no andc_ name=' $c_name'
andr ank=1" )ordie(@my sqli_error()
);echo" <table
border ='
1'>";echo"<t r
><th>sid</ th><th>name</ th><th>class</t
h
></tr>";whi l
e($row=my sqli_
fetch_ arr
ay (
$r esul t
)){echo"<tr><td
>";
echo
$row[ '
stud_ i
d']
;echo" </td><td>"; echo
$row[ '
name' ];echo"</td><td>" ;echo
$row[ '
class'];
echo" </td></tr>";}echo" </t
abl e>";my sqli
_close($
con); ?>

You might also like