Sie sind auf Seite 1von 8

SCHOOL OF COMPUTER SCIENCE AND ENGINEERING

Continuous Assessment Test – 2

Programme Name & Branch: B.Tech CSE (Common to all)


Course Code & Name: CSE3002 – INTERNET AND WEB PROGRAMMING Slot: E1
Exam Duration: 1 hr 30 minutes Maximum Marks: 50
Section – A (10 x 5 = 50 Marks)
Course
S.No. Question Outcome
(CO)
1. a) An HTML form for technical event registration portal contains input
fields like Registration number, Student Name, college URL, Mobile CO3
Number, E-Mail, Address with Pincode. Write the Javascript to perform
the validations using regular expressions based on the following:-
i. Checking registration number for alphanumeric with minimum
(6) and maximum (10) length only
ii. The Name must contain only letters
iii. Function to check whether a given URL is valid domain or not
iv. Mobile number must not exceed 10 numbers
v. Write a pattern to validate e-mail addresses
vi. Alphanumeric for address fields
vii. Pincode accepts only 6 digits (7 Marks)
b) If a user clicks on button Click to order, an alert dialogue box is CO3
displayed. Write the event handler to Modify the earlier onClick
example to include a flashing background colour before the alert
dialogue box. Make sure you restore the initial background colour of
choice by saving it first with a variable and using the variable to restore
the colour at the end. (3 Marks)

2. a) Implement simple calculator utility-program, which can be used to CO4


calculate person's Body Mass Index (BMI). Implement a simple form
(index.php) where user can input Name, E-Mail, DOB, weight (in
kilogramms) and height (in meters) as floating point. In the PHP-script
(output.php) called from form's action-method perform the following
i. Use String function to convert the given name to Upper case and
print in the output form
ii. Extract the user name from the specified email ID and compare
with name and return the Boolean value
iii. Use current date and calculate the Age from the DOB input
iv. Calculate the BMI and Show the Output as given below

(7 Marks)
b) Write a PHP program with function name deal which accepts CO4
arguments to find the best of the two products listed in the table for
purchase.
Product Details Quantity(s) Prize
Product1 70 1010
Product2 100 1220
(3 Marks)
3. a) A software company has asked the applicants to upload the Resume CO4
and Photograph in the online portal after the interview process. The
portal accepts the submission of files only after the key validations.
Write the appropriate HTML containing (Input types and button) and
PHP script to process the files based on the following
i. Specifiy the directory name as “Jobpost2019” where the files are
uploaded
ii. Check if File Name Already Exists or not
iii. The Resume should accept only Pdf / Doc and size of the file
must be within 1mb
iv. Allowed file types for the photograph(jpeg, jpg) and file size
within 250kb
v. Checks whether a file was uploaded via HTTP POST
(5 Marks)
b) Write a PHP program to demonstrate the concept of Cookies. Do the CO4
following
i. Create a cookie with a value CSE3002IWP.
ii. The cookie should expire in 10 days
iii. Check whether the cookie is present in the website. If so display
it else throw an error
iv. Check whether the cookie is enabled or not. Print the status
v. Delete the created cookie before an hour of the expiry date
(5 Marks)
4 Write the PHP script that allows an administrator to add items to the CO4
database of product items. Your script should check for product code
duplication before adding an entry. If the code is a duplicate then you
should report an error and the conflicting data that already exists.
Adding a product should be done via a form that communicates to a
PHP script on the server to generate appropriate SQL commands for
the MySQL server adding the requested data. Use the DB Server Details:
$dbhost = "localhost";
$dbuser = "admin";
$dbpass = "12345";
$db = "productdb";

5. Create a XML document to describe your academic details with domain CO5
specific vocabularies and Element declarations. Validate the document
with the DTD specification.
The academic details must contain the following:-
Registration Number , First Name , Last Name ,Degree & Branch Details
,CGPA ,Areas of Interest, List of Events Attended Details (Minimum 3 &
Maximum 5) ,Address Details , E-Mail ,Mobile Number
CSE3002 – INTERNET AND WEB PROGRAMMING

ANSWER KEY

E1 SLOT

1. a)
Empty filed
(input.value.length == 0)

Registration number
function alphanumeric(inputtxt)
{
var regno= /^[0-9a-zA-Z]+$/;

function lengthRange(inputtxt, minlength, maxlength)


{
var userInput = inputtxt.value;
if(userInput.length >= minlength && userInput.length <= maxlength)
{
return true;
}
else
{
alert("Please input between " +minlength+ " and " +maxlength+ " characters");
return false;
}
}

Name accepts only letters

var letters = /^[A-Za-z]+$/;


if(inputtxt.value.match(letters))

URL is valid or not

function is_domain(str)
{
regexp = /^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/i;

if (regexp.test(str))
{
return true;
}
else
{
return false;
}
}

Mobile number
var phoneno = /^\d{10}$/;
if(inputtxt.value.match(phoneno))
f($(this).val().length < 10)
{

return false;alert("not 10 digit")


}
else
{
return true;alert("10 digit")

E-mail addresses
function ValidateEmail(inputText)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

Pincode

function is_ZipCode(str)
{
regexp = /^[0-9]{6}?$/;

f($(this).val().length < 6)
{

return false;alert("not 6 digit")


}
else
{
return true;alert("6 digit")

1 b)
<FORM>
<INPUT type=button value="Click to order" onClick="window.alert('Purchase confirmed. Thank
you'); this.value = '[purchase confirmed]'"</FORM>

<INPUT type=button value="Click to order" onClick="var currentBack;


currentBack = document.bgColor; document.bgColor = 'blue';
document.bgColor = 'coral'; document.bgColor = 'blue';
window.alert('Purchase confirmed. Thank you')">

2 a)

Name
Strtoupper() and strcmp()

E-Mail
$mailid = 'abc@example.com';
$user = strstr($mailid, '@', true);

Age Calculation
$bday = new DateTime('11.4.1987'); // Your date of birth
$today = new Datetime(date('m.d.y'));
$diff = $today->diff($bday);
printf(' age : %d years, %d month, %d days', $diff->y, $diff->m, $diff->d);
?>

BMI Calcualtion
//Define variables and give initial values.
$height=0;
$width=0;

//Read values to variables from HTML-form.


$height=$_POST['height'];
$weight=$_POST['weight'];
//Calculate BMI.
$bmi=$weight / ($height * $height);

//Print result.
print("Body mass index is $bmi");
?>
<br /><br /><a href="index.htm">Back to examples</a>
</body>
</html>

2 b)
<?php
function deal ($quantity1, $quantity2, $prize1, $prize2)
{
$deal1 = $prize1 / $quantity1;
$deal2 = $prize2 / $quantity2;
return ($deal1 < $deal2);
}
$quantity1 = 70;
$quantity2 = 100;
$prize1 = 1010;
$prize2 = 1220;
if(deal($quantity1, $quantity2, $prize1, $prize2)) {
print("The Product1 deal is best!");
}
else
{
print("The Product2 deal is best!");
}
?>

3 a)
First, ensure that PHP is configured to allow file uploads.
In your "php.ini" file, search for the file_uploads directive, and set it to On:
file_uploads = On

<?php
$target_dir = "Jobpost2019/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

// Check if image file is a actual image or fake image Also for PDF
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 250000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "jpeg") {
echo "Sorry, only JPG, JPEG are allowed.";
$uploadOk = 0;
}
if ($uploadOk == 0)
{
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
HTTP Post
<?php
$file = "XYZ";
if(is_uploaded_file($file)) {
echo ("$file is uploaded via HTTP POST");
} else {
echo ("$file is not uploaded via HTTP POST");
}
?>

3 b)
<?php
$cookie_name = "CSE3002";
$cookie_value = "CSE3002IWP";
setcookie($cookie_name, $cookie_value, time() + (864000 * 30), "/"); // 86400 = 10 day
?>
<html>
<body>
<?php
if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is set!<br>";
echo "Value is: " . $_COOKIE[$cookie_name];
}
?>
</body>
</html>
setcookie("CSE3002IWP", "test", time() + 3600, '/');
<?php
if(count($_COOKIE) > 0) {
echo "Cookies are enabled.";
} else {
echo "Cookies are disabled.";
}
?>

// set the expiration date to one hour ago


setcookie("user", "", time() - 3600);

4. DB CONNECTION
function OpenCon()
{
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "12345";
$db = "sample";
$conn = new mysqli($dbhost, $dbuser, $dbpass,$db) or die("Connect failed: %s\n". $conn -> error);

return $conn;
}

function CloseCon($conn)
{
$conn -> close();
}

<?php
include("connect");
if($pid == "") die("No Product ID Submitted");
$query = "SELECT * FROM Product WHERE ProductID='$pid'";
$result = mysql_query($query);
?>
?php
// Check for content, if not query and display
if (mysql_num_rows($result) < 1) {
// product does not exist
if ($add_or_del == "add") {
// adding a product
echo "Product Does not already exist - adding $pid $desc";
$query = "INSERT INTO Product VALUES('$pid','$desc',$cost,$markup,$quantity)";
$result = mysql_query($query);
if ($result < 1) {
echo "<BR>".mysql_errno().": ".mysql_error()."<BR>";
die("<p><font size=+1 color=purple> Add Operation Failed </font>");
}
$query = "SELECT * FROM Product WHERE ProductID='$pid'";
$result = mysql_query($query);
} else {
if ($add_or_del == "del") {
// deleting a product
echo "<font size=+1 color=red> Product does not already exist - can't delete $pid </font>";
} else {
if ($add_or_del == "quantity_change") {
// quantity change of a product
} else {
die("not sure what you wanted! try <a href = \"index.php3\">here</a>");
}
}
}

5.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project>
<Student>
<RegNo>16BCE0001</RegNo>
<Name>
<Firstname>ABC</Firstname>
<Lastname></Lastname>
</Name>
<College>
<School>SCOPE</School>
<Course>Computer Science and Engineering</Course>
</College>
<CGPA>8.9</CGPA>
<AreasOfIntrest>
<Technical>Web Developement and Python</Technical>
<NonTechnical>Photography, Timelapses, Music, Gaming</NonTechnical>
</AreasOfIntrest>
<Events>
<Inter-college>Came first at state level Inspire Innovation Awards</Inter-college>
<Intra-College>Runner-up Inno VIT</Intra-College>
</Events>
<Address>
<DoorNo>188</DoorNo>
<Street>14th Street</Street>
<Area> Nagar </Area>
<District>Vellore</District>
<State>Tamil Nadu</State>
<PinCode>23222</PinCode>
</Address>
<Email>abc@gmail.com</Email>
<phnNo>1234567890</phnNo>
</Student>

DTD FILE CODE:

<?xml version="1.0" encoding="UTF-8"?>


<!ELEMENT RegNo (#PCDATA) #REQUIRED>
<!ELEMENT Name (Firstname, Surname, Lastname)>
<!ELEMENT Firstname (#PCDATA) #REQUIRED>
<!ELEMENT Surname (#PCDATA) #REQUIRED>
<!ELEMENT Lastname (#PCDATA) #REQUIRED>
<!ELEMENT College (School, Course)>
<!ELEMENT School (#PCDATA) #REQUIRED>
<!ELEMENT Course (#PCDATA) #IMPLIED>
<!ELEMENT CGPA (#PCDATA) #IMPLIED>
<!ELEMENT AreasOfIntrests ((Technical, NonTechnical)|(NonTechnical, Technical))>
<!ELEMENT Technical (#PCDATA) #IMPLIED>
<!ELEMENT NonTechnical (#PCDATA) #IMPLIED>
<!ELEMENT Events ((Inter-college,Intra-College)|(Intra-College,Inter-college))>
<!ELEMENT Inter-College (#PCDATA) #IMPLIED>
<!ELEMENT Intra-College (#PCDATA) #IMPLIED>
<!ELEMENT Address(DoorNo, Street, Area, District, State, PinCode)>
<!ELEMENT Email (#PCDATA) #REQUIRED>
<!ELEMENT phnNo (#PCDATA) #REQUIRED>

Das könnte Ihnen auch gefallen