Professional Documents
Culture Documents
ANSHUL GAUTAM
BCA
WEB BASED
PROGRAMMING
ASSIGNMENT FILE
Submitted By: Submitted To:
NAME: ANSHUL GAUTUM PRABHJOT KAUR
CLASS: BCA 2C Asst. prof.
BCA-2C
P ag e |2
ANSHUL GAUTAM
PROGRAM-7
Ques: Do form handling in PHP design a form for personal
information then submit & retrieve the form using $_GET,
$_POST, $_REQUEST
SOURCE CODE:
<html>
<head></head>
<body>
<?php
<h1>REGISTRATION FORM</h1>
<form action="registration_form.php" method="POST">
First name:
<input type="text" name="firstname"> <br>
Last name:
<input type="text" name="lastname">
<input type="submit" value="Submit">
?>
</form>
</body>
</html>
OUTPUT:
BCA-2C
P ag e |3
ANSHUL GAUTAM
PROGRAM-8
Ques: WAP to perform all four sorting
[i]
SOURCE CODE:
<html>
<head></head>
<body>
<?php
$numbers=array(4,6,2,22,11);
rsort($numbers);
$arrlength = count($numbers);
for($x=0;$x<$arrlength;$x++){
echo $numbers[$x];
echo "<br>";
}
?>
</body>
</html>
OUTPUT:
BCA-2C
P ag e |4
ANSHUL GAUTAM
[ii]
SOURCE CODE:
<html>
<head></head>
<body>
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
krsort($age);
echo"<br>";
?>
</body>
</html>
OUTPUT:
BCA-2C
P ag e |5
ANSHUL GAUTAM
[iii]
SOURCE CODE:
<html>
<head></head>
<body>
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
asort($age);
echo"<br>";
?>
</body>
</html>
OUTPUT:
BCA-2C
P ag e |6
ANSHUL GAUTAM
[iv]
SOURCE CODE:
<html>
<head></head>
<body>
<?php
$numbers=array(4,6,2,22,11);
sort($numbers);
$arrlength = count($numbers);
echo $numbers[$x];
echo "<br>";
?>
</body>
</html>
OUTPUT:
BCA-2C
P ag e |7
ANSHUL GAUTAM
PROGRAM-9
SOURCE CODE:
<html>
<head></head>
<body>
<?php
// Reset the file pointer to the beginning of the file using fseek()
fseek($file, 0);
BCA-2C
P ag e |8
ANSHUL GAUTAM
OUTPUT:
BCA-2C
P ag e |9
ANSHUL GAUTAM
PROGRAM-10
Ques: WAP to showcase the use of contructor
destructor in php oops?
CONTRUCTOR
SOURCE CODE:
<?php
class Fruit {
public $name;
public $color;
BCA-2C
P a g e | 10
ANSHUL GAUTAM
OUTPUT:
BCA-2C
P a g e | 11
ANSHUL GAUTAM
DESTRUCTOR
SOURCE CODE:
<?php
class Fruit {
public $name;
public $color;
OUTPUT:
BCA-2C
P a g e | 12
ANSHUL GAUTAM
PROGRAM-11
Ques: WAP to create a MySql database.
SOURCE CODE:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$conn->close();
?>
OUTPUT:
BCA-2C
P a g e | 13
ANSHUL GAUTAM
PROGRAM-12
Ques: WAP to create a table and insert few records into it
using form.
SOURCE CODE:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password,
$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->close();
?>
BCA-2C
P a g e | 14
ANSHUL GAUTAM
OUTPUT:
BCA-2C
P a g e | 15
ANSHUL GAUTAM
PROGRAM-13
Ques: Write a program to select all the records and display
the table.
SOURCE CODE:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password,
$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " .
$row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
BCA-2C
P a g e | 16
ANSHUL GAUTAM
OUTPUT:
BCA-2C
P a g e | 17
ANSHUL GAUTAM
PROGRAM-14
Ques: WAP to modify (delete/modify/add) a table.
SOURCE CODE:
• Delete
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDBPDO";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username,
$password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn = null;
?>
OUTPUT:
BCA-2C
P a g e | 18
ANSHUL GAUTAM
• Modify
SOURCE CODE:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDBPDO";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username,
$password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Prepare statement
$stmt = $conn->prepare($sql);
$conn = null;
?>
OUTPUT:
BCA-2C