complete
complete
<html>
<body>
<?php
?>
</html>
<?php
for($i=1;$i<=10;$i++)
echo"2 *$i=".(2*$i)."<br>";
?>
1
3) Write a program to print a Table of any Number.
<?php
for($i=1;$i<=10;$i++)
echo"5 *$i=".(5*$i)."<br>";
?>
4) Write a program to create a Table with Colors name and their respective colors.
<html>
<body>
<table>
<tr>
<td>pink</td>
<tdstyle="background-color:pink;width:50%"></td>
</tr>
<tr>
<td>
<?php echo'red';
?>
2
</td>
<tdstyle="background-color:
<?php echo'red'
?>;width:
<?php
echo'50%'?>"></td>
</tr>
<?php
echo'<tr><td>blue</td><tdstyle="background-color:blue;width:50%"></td></tr>';
?>
</table>
</body>
</html>
5) Write a program to enter two Number and display the greatest one.
<html>
<body>
<form method="POST"action="bigger.php">
<input type="submit"value="Greatest"><br>
3
</form>
</body>
</html>
PHP CODE
<html>
<body>
<?php
$x=$_POST["num1"];
$y=$_POST["num2"];
if($x>$y)
echo"$x is greater";
else
echo"$y is greater";
?>
</body>
</html>
10) Write a program to display a message corresponding to the day entered by the user using if-else
statement.
4
<html>
<body>
</form>
</body>
</html>
PHP CODE
<html>
<body>
<?php
$n=$_POST["num"];
if($n=="monday")
echo("gotoschool");
elseif
($n=="tuesday")
echo("havefun");
elseif
($n=="wednesday")
echo("exercise");
}
5
Else if
($n=="thursday")
echo("studywell");
else
echo("ENJOY
");
?>
</body>
</html>
7)Write a program to display a message corresponding to the day entered by the user using switch
statement.
<?php
$d=$_POST['num'];
switch ($d)
{
6
case "Monday":
echo"today is monday";
break;
case "Tuesday":
echo"today is tuesday";
break;
case "Wednesday":
echo"today is wednesday";
break;
case "Thursday":
echo"today is thursday";
break;
case "Friday":
echo"today is friday";
break;
case "Saturday":
echo"today is saturday";
break;
case "Sunday":
echo"today is sunday";
break;
default:
?>
HTML CODE
<body>
7
<form method="POST" action="7.php">
</form>
</body>
</html>
8) Write a program to check whether the number entered by the user is positive or negative.
<html>
<body>
<?php
$number=$_POST['num'];
if ($number > 0)
Else if($number<0)
8
echo"<p>$number is a negative number";
else
?>
</body>
</html>
HTML CODE
<body>
</form>
</body>
</html>
9) Write a program to check whether the number entered by the user is even or odd using if-else
statement.
9
<html>
<body>
<?php
$number=$_POST['num'];
if($number%2==0){
echo"this number is
even:".$number."<br>";
}else{
?>
</body>
</html>
HTML CODE
<body>
</form>
</body>
</html>
10) Write a program to check whether the number entered by the user is even or odd using switch
statement.
10
<html>
<body>
<?php
$number=$_POST['num'];
switch ($number % 2)
case 0:
echo"$number is even.";
break;
case 1:
echo"$number is odd.";
break;
?>
</body>
</html>
HTML CODE
<body>
</form>
</body>
</html>
11) Write a program to display a table whose number of rows and columns are entered by the user.
11
<body>
name="num"><br>
</form>
</body>
</html>
PHP CODE
<html>
<body>
<?php
$rows=$_POST['num'];
$columns=$_POST['num'];
echo"<table>";
for($i=1;$i<=$rows; $i++)
echo"<tr>";
for($j=1;$j <=$columns;$j++)
echo"<td>Row$i,Col $j</td>";
echo"</tr>"; }
echo"</table>";
?>
12
</body>
</html>
12) Write a program to enter rupees in textbox and convert it into dollars using PHP.
<?php
$rupee=$_POST["num"];
$dollar=$rupee*84;
echo $dollar;
?>
HTML CODE
<html>
<body>
<input type="submit"value="click">
</form>
</body>
</html>
13) Write a program to enter a temperature in Celsius in textbox and convert it into Fahrenheit
using PHP
13
<html>
<body>
</form>
</body>
</html>
PHP CODE
<html>
<body>
<?php
$a=$_POST["num"];
$b=($a*(9/5))+32;
echo $b;
?>
</body>
</html>
14) Write a program to enter a color in textbox and using PHP make that color as the background.
14
<?php
$col=$_POST["color"];
?>
<bodystyle="backgroud
?>">
</body>
</html>
HTML CODE
<html>
<body>
</form>
</body>
</html>
15) Write a program to set the colour of div (colour taken from user).
15
<html>
<head>
</head>
<body>
<form method="post">
<input type="text"id="color"name="color"placeholder="e.g.,red,#ff0000">
<button type="submit">SetColor</button>
</form>
<divstyle="width:200px;height:100px;background-color:<?phpechoisset($_POST['color'])?
</div>
</body>
</html>
16) Write a program to calculate the factorial of a number entered by the user using for loop.
16
<html>
<body>
</form>
</body>
</html>
PHP CODE
<html>
<body>
<?php
$fact=1;
$num=$_POST['num']; for($i=1;$i<=$num;$i++)
$fact=$fact*$i;
?>
</body>
</html>
17) Write a program to calculate the factorial of a number entered by the user using while loop.
17
<?php
$number=5;
if($number<0)
else{
$factorial=1;
$count=1;
while($count<=$number)
$factorial=$factorial*$count;
$count++;
?>
HTML CODE
<html>
<body>
<form method="POST"action="17.php">
<input type="submit"value="click"><br>
</form>
</body>
</html>
18
18) Write a program to find factorial of the number entered by the user, using do-while loop.
<?php
$number=$_POST['num'];
if ($number < 0)
else
$factorial=1;
$count=1; do
$factorial=$factorial*$count;
$count++;
}while($count<=$number);
?>
HTML CODE
<html>
<body>
<form method="POST"action="18.php">
<input type="submit"value="click"><br>
</form>
</body>
19
</html>
19) Write a program to print the fibonacci series of a number enetered by the user.
<?php
$n=$_POST['num'];
function fibo($n)
if($n<=1)
Return $n;
else
return(fibo($n-1)+fibo($n-2));
}
for($i=0;$i<10;$i++)
{
echo fibo($i)."<br>";
?>
HTMl
CODE :
<html>
<body>
</form>
20
</body>
</html>
<?php
for($i=0;$i<=5;$i++)
for($j=1;$j<=$i;$j++)
Echo $j;
echo"<br>";
?>
21
21) Write a program to create the following pattern:-
<html>
<body>
<?php
for($i=5;$i>=1;$i--)
for($j=1;$j<=$i;$j++)
echo$j;
echo("<br>");
?>
</body>
</html>
22
22) Write a program to create the following pattern:-
<html>
<body>
<?php
for($i=1;$i<=9;$i++)
echo'1';
echo'<br>';
for($i=1;$i<=9;$i++)
echo'1 1';
echo'<br>';
for($i=1;$i<=9;$i++)
23
echo'1';
?>
</body>
</html>
<html>
<body>
<?php
24
for($i=1;$i<=5;$i++)
for($j=1;$j<=5-$i;$j++)
echo'  ';
for($j=1;$j<=$i;$j++)
echo$j;
for($j=$i-1;$j>=1;$j--)
echo$j;
echo'<br>';
for($i=4;$i>=1;$i--)
for($j=5-$i;$j>=1;$j--)
echo'  ';
for($j=1;$j<=$i;$j++)
echo$j;
for($j=$i-1;$j>=1;$j--)
25
{
echo$j;
echo'<br>';
?>
</body>
</html>
<?php
$num1=5;
$num2=5;
$num3=$num1+$num2;
$num4=$num1-$num2;
$num5=$num1/$num2;
$num6=$num1*$num2;
$num7=$num1%$num2; echo
?>
<?php
$bestie=array('sahil','aman','arsh','palak','ankita','unnati');
26
foreach( $bestie as $a )
Echo $a."<br>";
?>
<html>
body>
<?php
$besties=array
'a'=>'amanjeet',
'b'=>'arshdeep
27
'c'=>'palak');
Echo $besties['a']."<br>";
Echo$besties['b']."<br>;
echo $besties['c'];
?>
</body>
</html>
<?php
$numbers=array(10,20,30,40);
$sum="";
foreach($numbers as $value)
$sum+=$value;
?>
28
28) Write a program to convert the string entered by the user into an array.
<?php
$string="arsh";
$array=str_split($string);
Echo $a."<br>";
?>
<?php
$student = array("arsh","aman","palak");
$arrlength=count($student);
echo current($student)."<br>";
echo next($student)."<br>";
echo prev($student)."<br>";
for($x=0;$x<$arrlength;$x++
echo $student[$x];
echo "<br>";
29
}
echo
reset($student)."<br>";
echo
end($student)."<br>";
?>
PHP CODE
<?php
$course=array("php"=>"bca","business"=>"bba","information"=>"btech tech");
$iteration->rewind();
while($iteration->valid())
$iteration->next();
30
31. Write a program to Create Multidimensional Array and Display its elements.
<?php
$marks=array("
arsh"=>array(
"Maths"=>50,
"java"=>99),
"aman"=>array(
"Maths"=>92,
"java"=>79),
"palak"=>array(
"Maths"=>62,
"java"=>89) );
echo $marks['arsh']['Php'].'<b';
echo"Marks of aman in
Maths:";
echo$marks['aman']['Maths'].'<b';
echo $marks['palak']['java'].'<br>';
?>
31
32. Write a program to use String Functions in PHP.
<?php
$str1="ArshdeepKaur";
$str2=empty($str1);
$str3="aman"; echo
echo"<br>";
echo str_repeat($str1,3);
echo "<br>";
echostrcmp($str1,$str3);
echo "<br>";
echostr_word_count($str1);
echo "<br>";
echostr_replace("palak","am
echotrim($str1);
echo "<br>";
echostrtolower($str1);
echo "<br>";
32
echo strtoupper($str1);
echo "<br>";
echoucfirst($str1);
echo "<br>";
echoucwords($str1);
echo "<br>";
?>
<?php
$num1=3.4;
33
$num2=5;
echoceil($num1);
echo "<br>";
echo floor($num1);
echo "<br>";
echo abs($num1);
echo "<br>";
echo pow($num1,$num2);
echo "<br>";
echo log(4,2);
exp(2);
echo"<br>";
echorand(2.5,2.0);
echo "<br>";
echobindec(1000);
echo "<br>";
echodecbin(15);
echo "<br>";
echo decoct(9);
echo "<br>";
echodechex(10);
echo "<br>";
echohexdec(15);
echo "<br>";
34
echooctdec(8);
echo "<br>";
printf("%4d",6);
echo "<br>";
?>
34. Write a program to create Registration form,insert,and display the values of the same usng PHP
<html>
<body>
<tr><td>ID</td>
<tr><td>Name</td>
<tr><td>Hobbies</td>
<tr><td>Course</td><td><select name="course">
value="BCA3">BCA 3</option>
</select></td></tr>
<tr><td>Marks</td>
<tr><td>Email</td>
<tr><td>Password</td>
</form>
</table>
</body>
</html>
PHP CODE
<?php
echo $_POST["id"]."<br>";
36
echo $_POST["txtname"]."<br>";
echo $_POST["gender"]."<br>";
$arr=$_POST["hobbies"];
foreach($arr as $a){
echo "<br>";
echo $_POST["course"]."<br>";
echo $_POST["txtemail"]."<br>";
echo $_POST["txtpass"]."<br>";
$eng=$_POST["eng"];
$math=$_POST["math"];
$hin=$_POST["hin"];
$pun=$_POST["pun"];
$sst=$_POST["sst"];
$per=(($eng+$math+$hin+$pun+$sst)/500)*100;
echo $per;
?>
</body>
</html>
37
35) Write a program to create a table in database using PHP
<?php
$my=new mysqli("localhost","root","","arsh");
if($my==false)
die("error:couldnotconnecttodatabase");
if($result=$my->query($sql))
echo"Table created!!!";
else
$my->close();
?>
38
<?php
$mysqli=new mysqli("localhost","root","","arsh");
if($mysqli==false)
die("erroroccured");
VALUES(1,'arsh',19)";
if($mysqli->query($sql)===true)
echo$mysqli->affected_rows.'rowupdates!!!';
Else
echo"error";
$mysqli->close();
?>
39
37) Write a program to DELETE values in a database table using PHP.
<html>
<body>
<?php
$mysqli=newmysqli("localhost","root","","arsh");
if($mysqli==false)
die("error occured");
if($mysqli->query($sql)===true)
echo$mysqli->affected_rows. 'rowdeletes.!!!';
Else
echo"error";
$mysqli->close();
?>
</body>
</html>
40
38) Write a program to UPDATE values in a database table using PHP.
<?php
$mysqli=newmysqli("localhost","root","","arsh");
if($mysqli==false)
die("erroroccured");
if($mysqli->query($sql)===true)
Else
echo"error";
$mysqli->close();
?>
39) Write a program to display all the values of database table using SELECT statement in PHP.
?php
41
$var=new mysqli("localhost","root","","arsh");
if($var===false)
$qry="SELECT*from student";
if($result=$var->query($qry))
if($result->num_rows>0)
while($row=$result->fetch_array())
echo$row[0].":".$row[1].":".$row[2]."<br>";
$result->close();
else
else
$var->close();
?>
42
40) Write a program using functions to display all the values of database table in a Table.
<?php
functiondata()
$ptr=new mysqli("localhost","root","","arsh");
if($ptr==false)
if($result=$ptr->query($sql))
if($result->num_rows>0)
display($result);
$result->close();
Else
{
echo"no matching records";
Else
{
echo"could not execute $sql";
}
43
$ptr->close();
}
functiondisplay($result)
{
while($rows=$result->fetch_array())
echo"<tableborder='2'width='200'><tr>";
echo "<td>$rows[0]</td>";
echo"<td>$rows[1]</td>";
echo"<td>$rows[2]</td>";
echo "</tr></table>";
data();
?>
41. Write a program to create a registration form and insert those values into database.
HTML CODE
<html>
<body>
44
<table border="solid2px">
<tr><td>ID</td>
<tr><td>Name</td>
<input type="radio"name="gender"value="male">Male</td></tr>
<tr><td>Hobbies</td>
<tr><td>Course</td><td><select name="course">
<option value="BCA1">BCA1</option>
<option value="BCA2">BCA2</option>
<option value="BCA3">BCA3</option>
</select></td></tr>
<tr><td>Marks</td>
MATH
CN
<inputtype="number" name="cn"><br>
HISTORY
45
<tr><td>Email</td>
<tr><td>Password</td>
<td><input type="password"name="txtpass"></td></tr>
<tr><tdcolspan="2"align="center">
<input type="reset"value="reset">
<input type="submit"value="submit"></td></tr>
</form>
</table>
</body>
</html>
PHP CODE
<?php
$id=$_POST["id"];
$name=$_POST["txtname"];
$gender=$_POST["gender"];
$hobbyarr=$_POST["hobbies"];
$hobby=implode("",$hobbyarr);
$course=$_POST["course"];
$email=$_POST["txtemail"];
$pass=$_POST["txtpass"];
$php=$_POST["php"];
$math=$_POST["math"];
$java=$_POST["java"];
$cn=$_POST["cn"];
$history=$_POST["history"];
$per=(($php+$math+$java+$cn+$history)/500)*100;
46
$sqlptr=newmysqli("localhost","root","","arsh");
if($sqlptr==false)
values ($id,'$name','$gender','$hobby','$course','$email',$pass,$per)";
if($sqlptr->query($sql)==true)
else{
$sqlptr->close();
?>
47
42) Write a program to insert the details of three tables (STUDENT,BOOK,AND ISSUE) in HTML
form and insert those values into database using functions.
HTML CODE
<html>
<body>
<H3> STUDENT</H3>
STUDENT ID
STUDENT NAME
STREAM
<select name="stream">
<option value=""></option
<option value="BBA">BBA</option>
<option value="BSC">BSC</option>
<option value="BCA">BCA</option>
</select><br><br>
SUBJECT
<h3>BOOK</h3>
BOOKID<br><br>
BOOK NAME<br><br>
BOOK AUTHOR<br><br>
48
<h3>ISSUE</h3>
DATE OF ISSUE<br><br>
</form
</body>
</html>
PHP CODE
<html>
<body>
<?php
function retrieve ()
if($mysqli == false)
addstudent($mysqli);
addbook($mysqli);
addissue($mysqli);
$mysqli->close ();
$stuid=$_POST['ID'];
$stuname=$_POST['name'];
49
$stustream=$_POST['stream'];
$stusubject=$_POST['subject'];
VALUE($stuid,'$stuname','$stustream','$stusubject')";
if($mysqli->query($sql1)===true)
echo "inserteddddddddd";}
else{
$bid=$_POST['bid'];
$bname=$_POST['bname'];
$author=$_POST['Bauthor'];
VALUE($bid,'$bname','$author')";
if($mysqli->query($sql2)===true){
echo "inserteddddddddd";}
else{
$stuid=$_POST['ID'];
$bid=$_POST['bid'];
$dateissue=$_POST['date'];
VALUE($stuid,$bid,'$dateissue')";
if($mysqli->query($sql3)===true){
50
echo "inserteddddddddd";}
else{
retrieve();
?>
</body>
</html>
43) Write a program to create a login page and validate the username and password.
HTML CODE
<html>
<body>
</form>
</body>
</html>
PHP CODE
<?php
$name=$_POST["username"];
$pass=$_POST["password"];
$my=new mysqli("localhost","root","","arsh");
if($my==false)
if($result=$my->query($sql))
if($result->num_rows==1)
while($rows=$result->fetch_array())
if(strcmp($rows[0],$pass)==0)
else
52
echo "invalid password";
else
else
$my->close();
?>
53
44) Write a program to create a cookie in PHP.
<html>
<body>
<?php
if(isset($_COOKIE['email']))
Echo 'welcomeback,'.$_COOKIE['email'].'!';
else { setcookie('email','[email protected]',mktime()+129600,'/');
?>
</body>
</html>
45) Write a program to check how many times you have visited cookie.
<?php
if(isset($_COOKIE ['VisitCounter']))
54
{
setcookie("VisitCounter",$_COOKIE['VisitCounter']+1,time()+86400000,"/");
?>
HTML CODE
<html>
<body>
</body>
</html>
55
PHP CODE
<?php
$name=$_POST['txtname']; session_start();
if(isset($_POST['sessiondestroy']))
session_destroy();
} else
if(isset($_SESSION['USERNAME']))
foreach($_SESSION['USERNAME'] as $u)
else
$_SESSION['USERNAME'][]=$name;
?>
56
47) Write a program to print visit time in using sessions.
<html>
<body>
<?php
session_start();
date_default_timezone_set ("Asia/Calcutta");
if(!isset ($_SESSION['visits']))
else
$_SESSION['visits'][]=mktime();
?>
</body>
</html>
57
58
59