WS Ass3
WS Ass3
Telegram : @programming_1_2
Q1. Answer the following questions.
a) For what purpose forms are used?
Forms are used for collecting and submitting data from users on a website. They provide
a way for users to enter information, make selections, and interact with the website.
b) Describe the syntax of a form.
The syntax of a form in HTML typically consists of the <form> element with attributes for
specifying the form's action, method, and other optional attributes. Inside the form,
various form controls such as <input>, <select>, and <textarea> are used to create input
fields and user interface elements.
c) What is the purpose of forms submit button?
The purpose of a form's submit button is to initiate the submission of the form data to the
server. When a user clicks the submit button, the form data is sent to the server-side
script specified in the form's action attribute for processing.
d) What does PHP stand for?
PHP stands for Hypertext Preprocessor.
e) What are the delimiters that surround PHP server scripts?
PHP server scripts are surrounded by the <?php and ?> delimiters.
f) Describe the syntax of PHP variables.
The syntax of PHP variables starts with a dollar sign ($) followed by the variable name.
Variables in PHP are loosely typed, meaning they don't require explicit declaration or type
specification. For example:
bash
Copy code
$variableName = value;
g) What is the correct way to end a PHP statement?
The correct way to end a PHP statement is with a semicolon (;).
h) What are the correct ways to add a comment in PHP?
There are two ways to add comments in PHP:
Single-line comments: They are denoted by two forward slashes (//). Anything after the //
will be considered a comment on the same line.
Multi-line comments: They are enclosed between /* and */ and can span across multiple
lines.
Q2. Choose the correct answer.
1. In PHP you can use both single quotes ( ' ' ) and double quotes ( " " ) for strings.
a) True b) False
a) open("time.txt"); b) fopen("time.txt","a");
c) $my-Var d) myVar
a) True b) False
a) True b) False
<form>
<h2>Login</h2>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br>
<label>Gender:</label>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br>
<label for="job">Job:</label>
<select id="job" name="job">
<option value="teacher">Teacher</option>
<option value="engineer">Engineer</option>
<option value="student">Student</option>
<option value="other">Other</option>
</select><br>
index.html
<html>
<body>
</body>
</html>
add.php
<html>
<body>
?><br>
</body>
</html>
Q5. Write a PHP program that declares and initializes three arrays "A", "B"
and "C" of length 5 for each array. All arrays components are initialized to be
zeros. The program then assigns values to each array as follows:
• Cells of array A should contain a value equals to its index value
multiplied by 3.
• Cells of array B should contain a value equals to its index value
subtracted from 5.
• Cells of array C should contain a value equals to the sum of
corresponding cells of A and B.
The program shout prints out the three arrays.
<!DOCTYPE html>
<html>
<body>
<?php
$A = array_fill(0,5, 0);
$B = array_fill(0,5, 0);
$C = array_fill(0,5, 0);
</body>
</html>
Output :