You are on page 1of 15

UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA

MAD
MID- EXAM

From: Wasif Ali


18-CP-71 Dated: -APR 22, 2021
Question 1
• Code: -
<!DOCTYPE html>
<head>
<title>Question no 1</title>
</head>
<body>
<main>
<form action="" method="POST">
<div>
<center>
<h1>Question No. 1</h1>
<h2> By Wasif Ali (18-CP-71) </h2>
</div>
<center>
<label>Your Text :</label><input type="text" placeholder="Enter Text Here..." name
="data"><br>
<br>
<button type="submit" name="create">Creating</button>
<button type="submit" name="fileopen">Opening</button>
<button type="submit" name="fileread">Reading</button>
<button type="submit" name="filewrite">Writing</button>
<button type="submit" name="fileappend">Appending</button>
<button type="submit" name="fileclose">Closing</button>
<button type="submit" name="filedelete">Deleting</button>
<button type="submit" name="filetruncate">Truncating File</button>

</div>
</center>
</body>
</html>
<?php
if (isset($_POST['create'])) {
$inputtext = $_POST['data'];
$inputFileName = "Question1.txt";
$inputFileHandler = fopen($inputFileName,'a+') or die("Warning! File not accessible");
fwrite($inputFileHandler, "Entered Text: ".$inputtext."\n--------------------------------
----------------------------------------------\n");
fclose($inputFileHandler);
}

if (isset($_POST['fileopen'])) {
$inputFileName = "Question1.txt";
$inputFileHandler = fopen($inputFileName,'r+') or die("Warning! File not accessible");
$fileData = fread($inputFileHandler, filesize($inputFileName));
fclose($inputFileHandler);
PAGE 1
echo "<h2>Data Received:</h2>";
echo $fileData;
}

if (isset($_POST['filedelete'])) {
$inputFileName = "Question1.txt";
unlink($inputFileName);
}

if (isset($_POST['filetruncate'])) {
$inputFileName = "Question1.txt";
$inputFileHandler = fopen($inputFileName,'w') or die("Warning! File not accessible");
fclose($inputFileHandler);
}

if (isset($_POST['fileclose'])) {
$inputFileName = "Question1.txt";
$inputFileHandler = fopen($inputFileName,'r+') or die("Warning! File not accessible");
fclose($inputFileHandler);
}
?>

• Result: -

PAGE 2
Question 2
• Code: -
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Question No 2</title>
<link rel="stylesheet" href="">
<style>
body>section{
width: 100%;
padding: 30px;
}

body>section p{
line-height: 40px;
font-size: 25px;
}
</style>

PAGE 3
</head>
<body>
<main>
<section id="StudentSection">
<form action="" method="POST">
<div class="first">
<div>
<h1>By 18-CP-71</h1>
</div>
</div>
<hr>
<div class="second">
<input type="text" placeholder="Student Name" name="Name" maxlength="15"><br>
<input type="text" placeholder="Father Name" name="FatherName"maxlength="10"><br>
<input type="text" placeholder="Home Address" name="Email" maxlength="20"><br>
<input type="text" placeholder="Phone no" name="Password" maxlength="15"><br>
<input type="text" placeholder="Date" name="Date" maxlength="15"><br>
</div>
<h2>
</h2>
<label for="Gender">Sex</label>
<div>
<label for="Female">Female</label>
<input type="radio" name="Gender" value="Female">
<label for="Male">Male</label>
<input type="radio" name="Gender" value="Male">
</div>
</di>
<h2>
</h2>
<button type="submit" name="submitStudent">
Submit
</button>
<button type="submit" name="submitStudent">
Reset
</button>
<button type="submit" name="submitStudent">
Search by Student name
</button>
<button type="submit" name="submitStudent">
Update by Phone Number
</button>
<button name="readFile">Show All the Record</button>
</div>
</form>
</section>
</main>
<section>

PAGE 4
<p>
<?php
if(isset($_POST["submitStudent"])){
//data from the form
$filePath = 'student.txt';

$firstname = $_POST["Name"];
$surName = $_POST["FatherName"];
$eneterdEmail = $_POST["Email"];
$enteredPwd = $_POST["Password"];
$dateOfBirth = $_POST["Date"];
$gender = $_POST["Gender"];

//labels for the data


$fName = "Name: ";
$sName = "FatherName: ";
$emailLabel = "Email: ";
$pwdLabel = "Password: ";
$dob = "Date of Birth: ";
$gend = "Gender: ";
$dots = '................................................
';

// create handler
$fhandler = fopen($filePath, 'a') or die("can not open the file");

// wirte in the file


fwrite($fhandler, $fName.$firstname.'
'.$sName.$surName.'
'
.$emailLabel.$eneterdEmail.'
'.$pwdLabel.$enteredPwd.'
'
.$dob.$dateOfBirth.'
'.$gend.$gender.'
'.$dots);

// close the file


fclose($fhandler);

}
if(isset($_POST["readFile"])){
$filePath = 'Student.txt';
$handler = fopen($filePath, '
') or die ("can not open the file");
$output = fread($handler, filesize($filePath));
echo $output;
fclose($handler);

PAGE 5
}
?>
</p>
</section>
</body>
</html>

• Result: -

PAGE 6
Question 3
• Code: -
<!DOCTYPE html>
<html>

<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Question 3</title>
<style>
body {
font-family: Calibri, Helvetica, sans-serif;
}

.container {
margin: 50px;
padding: 50px;
background-color: lightblue;
}

input[type=text],
input[type=password],
textarea {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
display: inline-block;
border: none;
background: #f1f1f1;
}

input[type=text]:focus {
background-color: orange;
outline: none;
}

div {
padding: 10px 0;
}

hr {
border: 1px solid #f1f1f1;
margin-bottom: 25px;
}

.btn {
display: flex;
PAGE 7
}

.registerbtn {
background-color: #4CAF50;
color: white;
padding: 16px 20px;
margin: auto;
border: none;
cursor: pointer;
width: 15%;
opacity: 0.9;
}

.a {
outline: none;
border: none;
}

.registerbtn:hover {
opacity: 1;
}
</style>
</head>

<body>
<form action="q3.php" method="POST">
<div class="container">
<center>
<h1> Registeration Form</h1>
</center>
<hr>
<label> Student Name </label>
<input type="text" name="studentname" placeholder="Student Name" maxlength="15" r
equired />
<label> Father Name: </label>
<input type="text" name="fathername" placeholder="Father Name" maxlength="15" req
uired />
Current Address :
<textarea name="address" rows="2" placeholder="Current Address" maxlength="50" re
quired>
</textarea>
<div>
<label>
Gender :
</label><br>
<input type="radio" value="Male" name="gender" checked> Male
<input type="radio" value="Female" name="gender"> Female

PAGE 8
</div>
<label>
Phone Number:
</label>
<input type="text" name="phone" placeholder="phone no." maxlength='15' required /
>

<div class="btn">
<button type="submit" name='submit' class="registerbtn">Submit</button>
<button type="reset" class="registerbtn">Reset</button>
<button type="search" class="registerbtn">Search by Student Name</button>
<button type="update" class="registerbtn">Update by Phone Number</button>
<form action="read.php" method="get">
<a href='read.php' type="show" action="show" name="show" class="registerb
tn">Show all Record</a>
</form>
</div>

<?php
if (isset($_POST['submit'])) {
$filePath = 'data.txt';
$eneteredSName = $_POST["studentname"];
$eneteredFName = $_POST["fathername"];
$eneteredAddress = $_POST["address"];
$eneteredGender = $_POST["gender"];
$eneteredPhone = $_POST["phone"];
$studentLabel = "Student Name : ";
$fatherLabel = "Father Name : ";
$addLabel = "Address : ";
$genderLabel = "Gender : ";
$phoneLabel = "Phone No. : ";
$dots = '................................................<br>';

$fhandler = fopen($filePath, 'a') or die("Can not open the file");

fwrite($fhandler, $studentLabel . $eneteredSName . '<br>' .


$fatherLabel . $eneteredFName . '<br>' .
$addLabel . $eneteredAddress . '<br>' .
$genderLabel . $eneteredGender . '<br>' .
$phoneLabel . $eneteredPhone . '<br>'
. $dots);
fclose($fhandler);
}
?>
</form>
</body>
</html>

PAGE 9
• Result:

PAGE 10
Question 4 (Variable with local scope)
• Code: -
<!DOCTYPE html>
<html>
<head>
<title>Question 4</title>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<style>
body {
font-size: 17px;
font-family: arial;
background: #f4f4f4;
line-height: 1.5em;
}
header {
background: #333;
color: #fff;
padding: 20px;
text-align: center;
border-bottom: 4px #000 solid;
margin-bottom: 10px;
}
#container {
width: 90%;
margin: auto;
padding: 10px;
}

#box {
background: #333;
color: #fff;
width: 500px;
height: 90px;
padding: 40px;
text-align: center;
}

#box2 {
background: red;
width: 100px;
height: 100px;
position: relative;
}
</style>
</head>
<body>
PAGE 11
<header>
<h1>Effects and Anime | Using jQuery</h1>
</header>
<div id="container">
<button id="btnFadeOut">Fade Out</button>
<button id="btnFadeIn">Fade In</button>
<button id="btnFadeTog">Fade Toggle</button>

<hr />

<button id="btnSlideUp">Slide Up</button>


<button id="btnSlideDown">SlideDown</button>
<hr />

<div id="box"><h1>Hello Taxilians! I am Wasif</h1></div>

<hr />

<script>
$(document).ready(function () {
$('#btnFadeOut').click(function () {
$('#box').fadeOut(3000, function () {
$('#btnFadeOut').text('Its Gone')
})
})
$('#btnFadeIn').click(function () {
$('#box').fadeIn(3000)
})
$('#btnFadeTog').click(function () {
$('#box').fadeToggle(1000)
})
$('#btnSlideDown').click(function () {
$('#box').slideDown(3000)
})
$('#btnSlideUp').click(function () {
$('#box').slideUp(3000)
})
$('#btnSlideTog').click(function () {
$('#box').slideToggle(3000)
})
$('#btnStop').click(function () {
$('#box').stop()
})

$('#moveRight').click(function () {
$('#box2').animate({
left: 500,
height: '300px',

PAGE 12
width: '300px',
opacity: '0.5',
})
})

$('#moveLeft').click(function () {
$('#box2').animate({
left: 0,
height: '100px',
width: '100px',
opacity: '1',
})
})

$('#moveAround').click(function () {
var box = $('#box2')
box.animate({
left: 300,
})
box.animate({
top: 300,
})
box.animate({
left: 0,
top: 300,
})
box.animate({
left: 0,
top: 0,
})
})
})
</script>
</body>
</html>

• Result: -

PAGE 13
PAGE 14

You might also like