Beruflich Dokumente
Kultur Dokumente
Short Questions
Ans.
1) GET method passes request parameter in URL String while POST method passes
request parameter in request body.
2) GET request can only pass limited amount of data while POST method can pass
large amount of data to server.
3) GET request can be bookmarked and cached unlike POST requests.
4) GET is mostly used for view purpose (e.g. SQL SELECT) while POST is mainly use
for update purpose (e.g. SQL INSERT or UPDATE).
Ans.
Cascading Style Sheet(CSS) is used to set the style in web pages which contain HTML
elements. It sets the background color, font-size, font-family, color, … etc property of
elements in a web pages.
There are three types of CSS which are given below:
Inline CSS
Internal or Embedded CSS
External CSS
Ans.
Here are few high-level differences between DOM parser and SAX Parser in Java:
1) DOM parser loads whole XML document in memory while SAX only loads a small
part of the XML file in memory.
2) DOM parser is faster than SAX because it access whole XML document in memory.
3) SAX parser in Java is better suitable for large XML file than DOM Parser because it
doesn't require much memory.
4) DOM parser works on Document Object Model while SAX is an event based XML
parser.
Ans.
PHP is a server scripting language, and a powerful tool for making dynamic and
interactive Web pages.
strtolower Used to convert all string characters to lower echo strtolower( outputs benjamin
case letters 'Benjamin');
strtoupper Used to convert all string characters to upper echo outputs GEORGE W
case letters strtoupper('george w BUSH
bush');
Strlen The string length function is used to count the echo strlen('united 24
number of character in a string. Spaces in states of america');
between characters are also counted
Substr Used to return part of the string. It accepts three $my_var = 'This is a This is a re...
(3) basic parameters. The first one is the string really long sentence
to be shortened, the second parameter is the that I wish to cut
position of the starting point, and the third short';echo
parameter is the number of characters to be substr($my_var,0,
returned. 12).'...';
str_replace Used to locate and replace specified string echo str_replace that laptop is very
values in a given string. The function accepts ('the', 'that', 'the expensive
three arguments. The first argument is the text laptop is very
to be replaced, the second argument is the expensive');
replacement text and the third argument is the
text that is analyzed.
Syntax
define(name, value, case-insensitive)
Parameters:
<?php
define("GREETING", "Welcome to W3Schools.com!");
echo GREETING;
?>
Attributes
Attributes give the information about the elements. They can be specified only in the
element start tag and their values are enclosed strictly in double quotation-mark. This is
unlike HTML where attributes could be in single, double or without quotations.
Example:
< problem size=“huge” cause=“unknown” solution=“run away” >
If elements are the “nouns” of XML, then attributes are its “adjectives”.An Element can
have zero, one or more attributes. Also an attribute name can only appear once within
an element
Entities
Entity references are placeholders for other values that are otherwise reserved in the
language or that maybe misinterpreted. For example the less than (< ) and the greater
than ( > ) symbols are reserved for demarking the tags. If the entity description itself
contains one of these symbols the data would be misinterpreted. To avoid such a
scenario Entities are used. The ampersand (&) symbol is reserved to indicate start of an
entity.
& AMPERSAND
" QUOTATIONS
&apos APOSTROPHEE
9) How to find current date and time? & How to convert one date format into another in
PHP?
<?php
?>
<?php
echo "Today's date in various formats:" . "\n";
require(): If it cannot find the file that is referenced, the application will throw an error
and stop the execution. include(): If it cannot find the referenced file it will throw a
warning, but the application WILL CONTINUE execution. (sorry for the caps, they are to
emphasize) require_once & include_once work in the same way as include() and
require() with the difference that they are slower, since the loading of a file is prevented
more than once. This prevents the functions and variables from being rewritten and you
have an error associated with it. Normally these versions are used only when they are
necessary
11) What are simple and complex data types in XML Schema?
Simple Type User can independently define. This type is used when a
restriction is placed on an embedded simple type to create
and use a new type.
Complex User can independently define. This type is used when the
Type type has a child element or attribute.
A simple type is a type that only contains text data when expressed according to XML
1.0. This type can be used with element declarations and attribute declarations. The
embedded simple type is provided for in XML Schema Part 2. A restriction may be
placed on an embedded simple type to create a new, unique simple type.
On the other hand, a complex data type is a type that has a child element or attribute
structure when expressed according to XML 1.0. An element declaration may be used
with this type. There are no predefined complex type data types, so the user will
always define their own.
DTD can be classified on its declaration basis in the XML document, such as −
Internal DTD
External DTD
When a DTD is declared within the file it is called Internal DTD and if it is declared in a
separate file it is called External DTD.
Validation − It gives a way to check the validity of XML files by checking whether
the elements appear in the right order, mandatory elements and attributes are in
place, the elements and attributes have not been inserted in an incorrect way,
and so on.
Long Questions
Ans.
<!DOCTYPE html>
<html>
<head>
<title>Manual 10</title>
</head>
<body>
<br><br>
<br><br>
Select operation:
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
Output:
<?php
$num1=$_POST['number1'];
$num2=$_POST['number2'];
if($_SERVER["REQUEST_METHOD"]="POST")
if($_POST['r1']=='add')
echo $num1+$num2;
else if($_POST['r1']=='subtract')
echo $num1-$num2;
else if($_POST['r1']=='multiply')
echo $num1*$num2;
}
else if($_POST['r1']=='divide')
echo $num1/$num2;
else if($_POST['r1']=='modulo')
echo $num1%$num2;
?>
</form>
</body>
</html>
Ans.
Q. WAP to upload a file in server & get the name, temporary name, size and extension
of that file.
Sol:
HTML CODE
<html>
<body>
</form>
PHP CODE
<?php
$name = $_FILES["file"]["name"];
$size = $_FILES["file"]["size"];
$tmp_name = $_FILES["file"]["tmp_name"];
if (isset($name)) {
if(!empty($name))
$location = "uploads/";
if(move_uploaded_file($tmp_name, $location.$name)) {
if ($_FILES["file"]["size"]) {
} else{
?>
</body>
</html>
3. Write the schema for the following xml data using DTD Language and XML
Schema Language
<empdetails>
<emp id=”1”>
<name>kiran</name>
<designation>professor</designation>
<salary>50000</salary>
</emp>
<emp id=”2”>
<name>shyam</name>
<designation>Associate professor</designation>
<salary>45000</salary>
</emp>
</empdetails>
Ans.
<xs:schema>
<xs:complexType=”empType”>
<xs:sequence>
</xs:sequence>
</xs:complexType>
<xs:complexType=”empdetailsType”>
</xs:complexType>
<xs:element name=”empdetails” type=”empdetailsType”>
</xs:schema>
4) Create an XML Document for storing books information such as isbn number, title,
author, publisher and price.
<xml version=”1.0”
<books>
<book>
<isbn></isbn>
<title></title>
<author></author>
<publisher></publisher>
<price></price>
</book>
</books>
What is a Cookie?
A cookie is often used to identify a user. A cookie is a small file that the server embeds
on the user's computer. Each time the same computer requests a page with a browser,
it will send the cookie too. With PHP, you can both create and retrieve cookie values.
Syntax
setcookie(name, value, expire, path, domain, secure, httponly);
Only the name parameter is required. All other parameters are optional.
The following example creates a cookie named "user" with the value "John Doe". The
cookie will expire after 30 days (86400 * 30). The "/" means that the cookie is available
in entire website (otherwise, select the directory you prefer).
We then retrieve the value of the cookie "user" (using the global variable $_COOKIE).
To modify a cookie, just set (again) the cookie using the setcookie() function:
Delete a Cookie
To delete a cookie, use the setcookie() function with an expiration date in the past:
b)
A session is a way to store information (in variables) to be used across multiple pages.
When you work with an application, you open it, do some changes, and then you close
it. This is much like a Session. The computer knows who you are. It knows when you
start the application and when you end. But on the internet there is one problem: the
web server does not know who you are or what you do, because the HTTP address
doesn't maintain state.
Session variables solve this problem by storing user information to be used across
multiple pages (e.g. username, favorite color, etc). By default, session variables last
until the user closes the browser.
So; Session variables hold information about one single user, and are available to all
pages in one application.
Tip: If you need a permanent storage, you may want to store the data in a database.
Session variables are set with the PHP global variable: $_SESSION.
Next, we create another page called "demo_session2.php". From this page, we will
access the session information we set on the first page ("demo_session1.php").
Notice that session variables are not passed individually to each new page, instead they
are retrieved from the session we open at the beginning of each page (session_start()).
b) How to redirect a request from one PHP file to another PHP file with an example.
7) Write the schema for the following xml data using DTD Language and XML Schema
Language
<studentdetails>
<student rollno=”1”>
<name>kiran</name>
<college>KMIT</college>
<branch>CSE</branch>
</student>
<student rollno=”2”>
<name>shyam</name>
<college>CBIT</college>
<branch>ECE</branch>
</student>
</studentdetails>
9) Write a PHP program which takes username and password as input from html file
.Checks whether the user is a valid user or not with the data in the database. If the user
is valid user, it should redirect to welcome page else to failure page.
Ex1.html
<html>
<body>
</form>
</body>
</html>
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "WTDB";
// Create connection
// Check connection
if($conn->connect_error)
$first =trim($_POST['t1']);
$last = trim($_POST['t2']);
$_SESSION["suser"] = $first;
$stmt->execute();
$stmt->bind_result($u,$p);
if($stmt->fetch()==true)
$validuser=true;
else
$validuser=false;
$stmt->close();
$stmt->bind_param("s", $first);
$stmt->execute();
$stmt->bind_result($u1);
if($stmt->fetch()==true)
$userexists=true;
else
$userexists=false;
$stmt->close();
$conn->close();
if($validuser==true)
header("location:welcome.php");
else if($userexists==true)
header("location:pwdpage.php");
else
header("location:register.php");
?>
Ex1.php
<!DOCTYPE html>
<html>
<body>
</form>
Register.php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
// collect value of input field
$u = $_REQUEST['t1'];
$p = $_REQUEST['t2'];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "WTDB";
// Create connection
// Check connection
if ($conn->connect_error)
if($stmt->execute()==true)
$stmt->close();
$conn->close();
?>
</body>
</html>
Welcome.php
<?php
session_start();
echo "Hello,".$_SESSION["suser"];
?>
Pwdpage.php
<?php
?>
<contacts>
<person>
<name>peter</name>
<mobileno>99999999</mobileno>
</person>
<person>
<name>john</name>
<mobileno>88888888</mobileno>
</person>
</contacts>
<xs:schema>
<xs:complexType=”personType”>
</xs:complexType>
<xs:complexType=”contactsType”>
</xs:complexType>
</xs:schema>
<!ELEMENT contacts (person*)>
<!ELEMENT person(name,mobileno)>
12) Explain in detail the limitations of DTD Language and the strengths of XML Schema
Language.