0% found this document useful (0 votes)
32 views

PHP final file

Uploaded by

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

PHP final file

Uploaded by

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

MM INSTITUTE OF COMPUTER TECHNOLOGY AND BUSINESS MANAGEMENT

MAHARISHI MARKANDESWAR (DEEMED TO BE UNIVERSITY)


MULLANA - AMBALA , HARYANA (INDIA) – 133207
(Established under section 3 of the UGC Act 1956) (Accredited by NAAC
with Grade ‘A++’)

Practical No. 7

Aim:- Write a program sort ten numbers by using


arrays. Source Code:-
<?php
$arr=array(56,64,98,12,20,54,12,36,0,176);
echo count($arr);
sort($arr);
echo "<br>";

/*foreach($arr as $val) echo


" ".$val;*/
echo " sorting array elements are<br>";
for($i=0;$i<count($arr);$i++)
{
echo $arr[$i]." ";
}
?>

Output:-

1
MM INSTITUTE OF COMPUTER TECHNOLOGY AND BUSINESS MANAGEMENT
MAHARISHI MARKANDESWAR (DEEMED TO BE UNIVERSITY)
MULLANA - AMBALA , HARYANA (INDIA) – 133207
(Established under section 3 of the UGC Act 1956) (Accredited by NAAC
with Grade ‘A++’)

Practical No. 8

Aim:- Write a program to Print Alphabet Triangle Using range() Function.


Source Code:-

<html>
<body>
<h2>Alphabet triangle using range() function</h2>
<?php
echo "<h2>ist pattern</h2>";
$number=range("A","E")
; for($i=0;$i<=5;$i++){
for($j=5;$j>$i;$j--){
echo $number[$i];
}
echo "<br>";
}
echo "<h2>second pattern</h2>"; //represent same pattern above
/*for($i=0;$i<=4;$i++1
0){
for($j=$i;$j<=4;$j++){
echo $number[$i];
}

echo "<br>";
}

for($i=0;$i<=4;$i++)
{

2
MM INSTITUTE OF COMPUTER TECHNOLOGY AND BUSINESS MANAGEMENT
MAHARISHI MARKANDESWAR (DEEMED TO BE UNIVERSITY)
MULLANA - AMBALA , HARYANA (INDIA) – 133207
(Established under section 3 of the UGC Act 1956) (Accredited by NAAC
with Grade ‘A++’)

for($j=0;$j<=$i;$j++)
{echo $number[$i];
}
echo "<br>";
}
?>
</body>
</html>

Output:-

3
MM INSTITUTE OF COMPUTER TECHNOLOGY AND BUSINESS MANAGEMENT
MAHARISHI MARKANDESWAR (DEEMED TO BE UNIVERSITY)
MULLANA - AMBALA , HARYANA (INDIA) – 133207
(Established under section 3 of the UGC Act 1956) (Accredited by NAAC
with Grade ‘A++’)

Practical No.9
Aim:- Write a program to demonstrate math functions.
SourceCode:-
<html>
<body>
<h2>Math Functions </h2>
<?php
$num=80;
$num1=30;
$num3=5.2690;
$num2=min($num,$num1);
echo "Min number is ".$num2."<br>";
echo "Max number is ".max($num,$num1)."<br>";
echo "Square root of " .$num. " is
".sqrt($num)."<br>";
echo "Square root of " .$num1. " is
".sqrt($num1)."<br>"; echo "power of 100^50 is
".pow($num,$num1)."<br>"; echo "power of 100^3 is
".pow($num,3)."<br>";
echo "Ceil ".ceil($num3)."<br>";//rounds a number UP to the nearest
//integer
echo "floor ".floor($num3)."<br>";//rounds a number DOWN to the
//nearest integer
echo "floating ".round($num3)."<br>";//To round a floating-point
//number, look at the
//round() function.
echo (abs(10.8)."<br>");//it return absolute(positive) values of number

echo (abs(-10)."<br>");

4
MM INSTITUTE OF COMPUTER TECHNOLOGY AND BUSINESS MANAGEMENT
MAHARISHI MARKANDESWAR (DEEMED TO BE UNIVERSITY)
echo "returns remainder
MULLANA - AMBALA , HARYANA (INDIA) – 133207
(Established under section 3 of the UGC Act 1956) (Accredited by NAAC
with Grade ‘A++’)

".fmod($num,$num1)."<br>"; echo "returns


remainder ".fmod(16,9);
?>
</body>
</html>

Output:-

5
MM INSTITUTE OF COMPUTER TECHNOLOGY AND BUSINESS MANAGEMENT
MAHARISHI MARKANDESWAR (DEEMED TO BE UNIVERSITY)
MULLANA - AMBALA , HARYANA (INDIA) – 133207
(Established under section 3 of the UGC Act 1956) (Accredited by NAAC
with Grade ‘A++’)

Practical No. 10

Aim:-Write a program to demonstrate the concept of Classes and Objects.


Source Code:-
<html>
<body>
<h2>Classes and Objects in PHP</h2>
<?php
//error reporting(0);
class Practical10{
public $a=23;
public $b=67;
}
class Inherit extends Practical10{
function fun2(){
echo "the sum is ".$this->a+$this->b;// this keyword refers to
//the current object
}}
$obj=new Inherit();
$obj->fun2();
?>
</body>
</html>

Output:-

6
MM INSTITUTE OF COMPUTER TECHNOLOGY AND BUSINESS MANAGEMENT
MAHARISHI MARKANDESWAR (DEEMED TO BE UNIVERSITY)
MULLANA - AMBALA , HARYANA (INDIA) – 133207
(Established under section 3 of the UGC Act 1956) (Accredited by NAAC
with Grade ‘A++’)

Practical No. 11

Aim:- Create a login form with two text fields called “login” and
“password”When user enters “mmdu” as a user name and
“university “ as a password it should be redirected to a
Welcome.HTML page or Sorry.HTML in case of wrong username
and passwords
Source Code:-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<title>Document</title>
</head>
<body>
<h1>Enter your login details below--></h1>
<form action="data.php" method="post">
<label for="Username">Username</label>
<input type="text" name="Username" placeholder="Enter your
Username">
<label for="Password">Password</label>
<input type="password" name="Password" placeholder="Enter your
Password">
<button>Submit</button>
</form>

</body></html>

7
MM INSTITUTE OF COMPUTER TECHNOLOGY AND BUSINESS MANAGEMENT
MAHARISHI MARKANDESWAR (DEEMED TO BE UNIVERSITY)
MULLANA - AMBALA , HARYANA (INDIA) – 133207
(Established under section 3 of the UGC Act 1956) (Accredited by NAAC
with Grade ‘A++’)

File data.php
<?php
$servername="localhost";
$username="root";
$password="";
$conn = mysqli_connect($servername,$username,$password);
if($conn==FALSE){
echo " your connection with database is False";
}
else
{
$username = $_POST['Username'];
$password = $_POST['Password'];
$query = "SELECT * FROM `login`.`data` WHERE
`Username`='$username'AND `Password`='$password';";
$a=$conn->query($query);
$rows = mysqli_num_rows($a);
if($rows>0){
header('location:welcome.html');
}
else{ header('location:sorry.
html');
}

File:welcome.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

8
MM INSTITUTE OF COMPUTER TECHNOLOGY AND BUSINESS MANAGEMENT
MAHARISHI MARKANDESWAR (DEEMED TO BE UNIVERSITY)
MULLANA - AMBALA , HARYANA (INDIA) – 133207
(Established under section 3 of the UGC Act 1956) (Accredited by NAAC
with Grade ‘A++’)

<meta name="viewport" content="width=device-width, initial-scale=1.0">


<title>Document</title>
</head>
<body>
<h1>Welcome Your are now logged in</h1>
</body>
</html>
File: Sorry.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Your username or password is mismatched</h1> </body></html>

Output:-

9
MM INSTITUTE OF COMPUTER TECHNOLOGY AND BUSINESS MANAGEMENT
MAHARISHI MARKANDESWAR (DEEMED TO BE UNIVERSITY)
MULLANA - AMBALA , HARYANA (INDIA) – 133207
(Established under section 3 of the UGC Act 1956) (Accredited by NAAC
with Grade ‘A++’)

Practical No. 12

Aim:- How to connect to MYSQL using PHP? Write programs


for insertion, deletion, updates and other sql queries. Design front
endusing html.css and write php scripts for processing of data.
Source Code:-
<html>
<body>
<?php
echo "<h3>connetion with mysql</h3>";
$servername="localhost";
$username="root";
$password="";
$conn=mysqli_connect($servername,$username,$password);
if($conn==FALSE)
{
echo "failure in conncetion with DB";
}
else
{
echo " connection is successful with mysql";
}
?>
</body> </html>

Output:-

10
MM INSTITUTE OF COMPUTER TECHNOLOGY AND BUSINESS MANAGEMENT
MAHARISHI MARKANDESWAR (DEEMED TO BE UNIVERSITY)
MULLANA - AMBALA , HARYANA (INDIA) – 133207
(Established under section 3 of the UGC Act 1956) (Accredited by NAAC
with Grade ‘A++’)

<html>
<body>
<?php
echo "<h3>Creation of database</h3>";
$servername="localhost";
$username="root";
$password="";
$conn=mysqli_connect($servername,$username,$password);
$sql="CREATE DATABASE practical12";
$query=mysqli_query($conn,$sql);
if($query==FALSE)
{
echo "failure in creating DB";
}
else
{
echo " creation of DB is suceesfull";
}
?> </body>

Output:-

<html>
<body>
<?php
echo "<h3>Creation of table in database</h3>";$servername="localhost";
11
MM INSTITUTE OF COMPUTER TECHNOLOGY AND BUSINESS MANAGEMENT
MAHARISHI MARKANDESWAR (DEEMED TO BE UNIVERSITY)
MULLANA - AMBALA , HARYANA (INDIA) – 133207
(Established under section 3 of the UGC Act 1956) (Accredited by NAAC
with Grade ‘A++’)

$username="root";
$password="";
$database="practical12";
$conn=mysqli_connect($servername,$username,$password,$database);
$sql="CREATE TABLE `stuinfo` ( `username` VARCHAR(10)
NOT NULL , `password` VARCHAR(10) NOT NULL ,
PRIMARY KEY
(`username`));";
$query=mysqli_query($conn,$sql);
if($query==FALSE)
{
echo "failure in creating table in DB";
}
Else{
echo " creation of table in DB is suceesfull";
} ?>

Output:-

<html>

<body>
<?php
echo "<h3>Insertion in table</h3>";
$servername="localhost";
$username="root";
24
MM INSTITUTE OF COMPUTER TECHNOLOGY AND BUSINESS MANAGEMENT
MAHARISHI MARKANDESWAR (DEEMED TO BE UNIVERSITY)
MULLANA - AMBALA , HARYANA (INDIA) – 133207
(Established under section 3 of the UGC Act 1956) (Accredited by NAAC
with Grade ‘A++’)

$password="";
$database="practical12";
$conn=mysqli_connect($servername,$username,$password,$database
);
$sql="INSERT INTO stuinfo VALUES('Ritu','ritu@2002')";
$query=mysqli_query($conn,$sql); if($query==FALSE)
{
echo "failure in inserting values in table";
}

else
{
echo " insertion of values in table is suceesfull";
} ?>

<html>
<body>
<?php
echo "<h3>Deletion in table</h3>";
$servername="localhost";
$username="root";
$password="";
$database="practical12";

24
MM INSTITUTE OF COMPUTER TECHNOLOGY AND BUSINESS MANAGEMENT
MAHARISHI MARKANDESWAR (DEEMED TO BE UNIVERSITY)
MULLANA - AMBALA , HARYANA (INDIA) – 133207
(Established under section 3 of the UGC Act 1956) (Accredited by NAAC
with Grade ‘A++’)

$conn=mysqli_connect($servername,$username,$password,$database
);

$sql="DELETE FROM stuinfo WHERE username='ritu';";

$query=mysqli_query($conn,$sql); if($query==FALSE)
{
echo "failure in deletion of values in table";
}
else
{

echo " deletion of values in table is suceesfull";


}?

Output:-

<?php
echo "<h3>Updation in table</h3>";
$servername="localhost";
$username="root";
$password="";

24
MM INSTITUTE OF COMPUTER TECHNOLOGY AND BUSINESS MANAGEMENT
MAHARISHI MARKANDESWAR (DEEMED TO BE UNIVERSITY)
MULLANA - AMBALA , HARYANA (INDIA) – 133207
(Established under section 3 of the UGC Act 1956) (Accredited by NAAC
$database="practical12"; with Grade ‘A++’)

$conn=mysqli_connect($servername,$username,$password,$database
);
$sql="UPDATE stuinfo SET username='rahul', password='rahul@2002'
WHERE username='ritu';";
$query=mysqli_query($conn,$sql); if($query==FALSE)

echo "failure in updation of values in table";


}
else
{
echo " updation of values in table is suceesfull";
} ?>
Output:-

24

You might also like