Beruflich Dokumente
Kultur Dokumente
(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 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)
{
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)
{
1 b)
<FORM>
<INPUT type=button value="Click to order" onClick="window.alert('Purchase confirmed. Thank
you'); this.value = '[purchase confirmed]'"</FORM>
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;
//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.";
}
?>
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>