Web Programming using PHP, Semester 4(2020), Model examination, July 2022
1. HTML tags contain three main parts: opening tag, content and closing tag. But
some
HTML tags are unclosed tags. Container tag consists of opening
tag+content+closing tag. While empty tag is tag without content or a closing
tag. Container tags are used to enclose texts, images etc.
2. The new operator allows the developers to create an instance of a user-defined
object type or of one of the built-in object types that has a constructor function.
The new operator is an operator which denotes a request for memory allocation
on the Heap. If sufficient memory is available, new operator initializes the memory
and returns the address of the newly allocated and initialized memory to the
pointer variable. The new operator is used in Javascsript to create new objects. It
can also be used to create an array object.
3. Cookies are files that hold information about you, your web browser and your
behavior on the internet. They are tiny files stored on your PC or device, which
can be used by websites or web apps to tailor your online experience.To set a
cookie in PHP,the setcookie() function is used. The setcookie() function needs to
be called prior to any output generated by the script otherwise the cookie will not
be set. Syntax : setcookie(name, value, expire, path, domain, security);
4. Variables are used to store data, like string of text, numbers, etc. Variable values
can change over the course of a script. PHP automatically converts the variable to
the correct data type, depending on its value. In PHP, a variable is declared
using $ sign followed by variable name. A variable name must start with a letter or
the underscore character. A variable name cannot start with a number. A variable
name can only contain alpha-numeric characters and underscores (A-z, 0-9).
Eg:$var=10;
5. After a database and a table have been created, we can start adding data in them.
Syntax rules to follow:
The SQL query must be quoted in PHP
L E A R N . G R O W . E X C E L
String values inside the SQL query must be quoted
Numeric values must not be quoted
The word NULL must not be quoted
The INSERT INTO statement is used to add new records to a MySQL table:
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
6. <input> elements of type password provide a way for the user to securely enter a
password. The element is presented as a one-line plain text editor control in which
the text is obscured so that it cannot be read, usually by replacing each character
with a symbol such as the asterisk ("*") or a dot ("•")
Eg:<input type="password" id="pwd" name="pwd" minlength="8"><br><br>
7. Web servers are used to execute server side scripting. They are basically used
to create dynamic pages. It can also access the file system residing at web
server. Server-side environment that runs on a scripting language is a web-
server. Scripts can be written in any of a number of server-side scripting
language available. It is used to retrieve and generate content for dynamic
pages. It is used to require to download plugins. In this load times are generally
faster than client-side scripting. When you need to store and retrieve information
a database will be used to contain data. It can use huge resources of server. It
reduces client-side computation overhead. Server sends pages to request of
user/client.
Examples: PHP, Python etc.
8. An array is created using an array() function in PHP. There are basically three
types of arrays in PHP: Indexed or Numeric Arrays: An array with a numeric index
where values are stored linearly. Associative Arrays: An array with a string index
where instead of linear storage, each value can be assigned a specific key.
Eg: <?php
$cars = array("Volvo", "BMW", "Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>
9. HTML tables allow web developers to arrange data into rows and columns.
The <table> tag defines an HTML table.An HTML table consists of
one <table> element and one or more <tr>, <th>, and <td> elements.The <tr>
element defines a table row, the <th> element defines a table header, and the
<td> element defines a table cell.
<table>
<tr>
<th></th>
<th></th>
</tr>
</table>
L E A R N . G R O W . E X C E L
10. mysql_fetch_row()
Fetch a result row as an numeric array
<?php
include('db.php');
$query=mysql_query("select * from tb");
$row=mysql_fetch_row($query);
echo $row[0];
echo $row[1];
echo $row[2];
?>
mysql_fetch_array()
Fetch a result row as an associative array, a numeric array and also it fetches by
both associative & numeric array.
<?php
include('db.php');
$query=mysql_query("select * from tb");
$row=mysql_fetch_array($query);
echo $row['id'];
echo $row['username'];
echo $row['password'];
echo $row[0];
echo $row[1];
echo $row[2];
?>
11. In PHP, there are two functions that are used to put the contents of a file
containing PHP source code into another PHP file. These function are Include()
and Require(). These functions are the same if but they have one difference. The
difference is that the include() function produces a warning, but the script will
continue execution, while the require() function produces a warning and a fatal
error i.e. the script will not continue execution. These two functions are used to
put the data of a file into another PHP file before it is executed by the server.
Include() Function
The Include() function is used to put data of one PHP file into another PHP file. If
errors occur then the include() function produces a warning but does not stop the
execution of the script i.e. the script will continue to execute.
Require() Function
The Require() function is also used to put data of one PHP file to another PHP
file. If there are any errors then the require() function produces a warning and a
fatal error and stops the execution of the script i.e. the script will continue to
execute.
L E A R N . G R O W . E X C E L
12. A web server is a computer that runs websites. It's a computer program that
distributes web pages as they are requisitioned. The basic objective of the web
server is to store, process and deliver web pages to the users. This
intercommunication is done using Hypertext Transfer Protocol (HTTP). The basic
function of a web server is to host websites and to deliver web content from its
hosted websites over the internet. During the delivery of web pages, web servers
follow a network protocol known as hyper text transfer protocol (HTTP). Web
hosting service providers uses web servers to host multiple websites.
(6 x 3 = 18 Marks)
Section B
Answer any 4 questions. Each question carries 8 marks.
(Write in not less than 2 pages)
13. The String object allows the user to works with a series of characters; it wraps
JavaScript’s string primitive data type with a number of methods. sJavaScript
automatically converts between string primitives and String object.s
Syntax
var val = new String(string);
The String parameter is a series of characters that has been properly encoded.
String Length
slice() Method
substring() Method
substr() Method
14. The font property is a shorthand property for:
font-style
font-variant
font-weight
font-size/line-height
font-family
Explain each with example
15. The JavaScript method toString() converts an array to a string of (comma
separated)
array values. The join() method also joins all array elements into a string.
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
L E A R N . G R O W . E X C E L
document.getElementById("demo").innerHTML = fruits.toString();
</script>
16. Variables can store data of different types, and different data types can do
different things.PHP supports the following data types:
String
Integer
Float (floating point numbers - also called double)
Boolean
Array
Object
NULL
Resource
17. Error Report levels
These error report levels are the different types of error the user-defined error
handler can be used for:
Value Constant Description
1 E_ERROR A fatal run-time error. Execution of the script is
stopped
2 E_WARNING A non-fatal run-time error. Execution of the script is
not stopped
8 E_NOTICE A run-time notice. The script found something that
might be an error, but could also happen when
running a script normally
256 E_USER_ERROR A fatal user-generated error. This is like an
E_ERROR, except it is generated by the PHP script
using the function trigger_error()
512 E_USER_WARNING A non-fatal user-generated warning. This is like an
E_WARNING, except it is generated by the PHP script
using the function trigger_error()
1024 E_USER_NOTICE A user-generated notice. This is like an E_NOTICE,
except it is generated by the PHP script using the
function trigger_error()
2048 E_STRICT Not strictly an error.
8191 E_ALL All errors and warnings (E_STRICT became a part of
E_ALL in PHP 5.4)
18. Exceptions are used to change the normal flow of a script if a specified error
occurs. When an exception is triggered:
The current code state is saved
The code execution will switch to a predefined (custom) exception handler
L E A R N . G R O W . E X C E L
function
Depending on the situation, the handler may then resume the execution from
the saved code state, terminate the script execution or continue the script
from a different location in the code
proper exception code should include:
1. try - A function using an exception should be in a "try" block. If the exception
does not trigger, the code will continue as normal. However if the exception
triggers, an exception is "thrown"
2. throw - This is how you trigger an exception. Each "throw" must have at least
one "catch"
3. catch - A "catch" block retrieves an exception and creates an object
containing the exception information
19. Alert Box
Use the alert() function to display a message to the user that requires their
attention. This alert box will have the OK button to close the alert box.
alert("HELLO");
Confirm Box
The confirm() function displays a popup message to the user with two
buttons, OK and Cancel. The confirm() function returns true if a user has
clicked on the OK button or returns false if clicked on the Cancel button.
confirm("Do you want to save changes?")
Prompt Box
The prompt() function takes two string parameters. The first parameter is the
message to be displayed, and the second parameter is the default value
which will be in input text when the message is displayed.
var num = prompt("Please enter a number”);
20. There are two ways the browser (client) can send information to the web server.
The GET Method
The POST Method
The GET Method
In PHP, the $_GET variable is used to collect values from HTML forms using
method get.Information sent from an HTML form with the GET method is displayed
in the browser's address bar, and it has a limit on the amount of information to
L E A R N . G R O W . E X C E L
send.
Write one example program
The POST Method
In PHP, the $_POST variable is used to collect values from HTML forms using
method post.Information sent from a form with the POST method is invisible and has
no limits on the amount of information to send.
Write one example program
The REQUEST Method
The $_REQUEST variable is a variable with the contents of $_GET and $_POST
and $_COOKIE variables.
<?php
//this will stay the same but the method in the form will change to you preference
from GET or POST
($_REQUEST['form name goes here'])
?>
21. Create database 'Employee' and add appropriate fields. Write a PHP script to list
the
details of Employee who got more than 80000 salaries
(4 x 8 = 32 Marks)
Section C
Answer up to 3 questions carrying 15 marks each. However, total marks for this
section should not exceed 30 marks. Marks scored over 30 will be ignored
22. With the help of an example explain each step for accessing the data from a
MySql
Database table?
Explain each step with Example
Create a database
Create a table
Load data into the table
Retrieve data from the table in various ways
L E A R N . G R O W . E X C E L
23. CSS element Selector
CSS id Selector
CSS class Selector
CSS Universal Selector
CSS Grouping Selector(Explain each in details with example)
24. Write the syntax and example of each Command: Create, Update, Insert, Delete
And
Select
25. a) branching statements in PHP
if statement - executes some code if one condition is true
if...else statement - executes some code if a condition is true and another
code if that condition is false
if...elseif...else statement - executes different codes for more than two
conditions
switch statement - selects one of many blocks of code to be executed
Write syntax and Example
b) Loops in PHP
while - loops through a block of code as long as the specified condition is true
do...while - loops through a block of code once, and then repeats the loop as
long as the specified condition is true
for - loops through a block of code a specified number of times
for each - loops through a block of code for each element in an array
Write syntax and Example
(Maximum 30 Marks)
Comments
Post a Comment