WorksheetsBlock 1: Lesson 1 – Conditional Structures (if/else)
Total questions: 134
Worksheet time: 1hrs 7mins
The main function of the if structure in PHP is:
Repeat a block of code in a loop.
Store data permanently on the server.
Execute a block of code only if a condition is true.
Define the basic structure of an HTML page.
Which keyword is used so the code runs an alternative block when the if condition is evaluated as false?
then
switch
elseif
else
In the athlete age classification exercise (Lesson 1/4), what classification is given for ages 18 or older?
Teen Team
Child Team
Baby Team
Adult Team
To check if a variable $idade is greater than or equal to 18 in PHP, which comparison operator inside the if is correct?
==
>
!=
>=
If the variable numeroequals10,whatwillbedisplayedbythecode<?phpif( numero > 10) { echo "Maior"; } else { echo "Não é Maior"; } ?>
Greater
Not Greater
Syntax error
Nothing
If the if condition is true, the code inside which pair of symbols is executed in PHP?
Quotes ""
Parentheses ()
Brackets []
Braces {}
What does Lesson 1 (of 4) highlight as essential for learning programming?
Memorize all PHP functions.
Do only visual design with CSS.
Ignore practice and focus on theory.
Programming requires logical sequence, training, and lots of practice.
If the variable $idade = 10, what will be the athlete’s classification according to the logic in Lesson 1/4 (Child Team is ages 6 to 12)?
Adult Team
Teen Team
Baby Team
Child Team
Which instruction correctly displays the message "Condition OK" on the screen using PHP?
print("Condition OK");
write("Condition OK");
console.log("Condition OK");
echo "Condition OK";
The expression inside if (the condition) usually returns which data type, determining whether the block will run?
String (text)
Integer (number)
Float (decimal)
Boolean (True/False)
What is the term used for the simulated server on your computer, accessed via the browser as http://localhost/... ?
Apache Server
XAMPP Manager
C:\xampp
Localhost
In PHP, which conditional control structure allows executing code when the condition is false?
else
while
if
for
For the condition ($numero < 5), which value will make the if block run?
5
10
5.5
4
Where should .php files (such as if_1.php from Lesson 1) be saved in the XAMPP folder structure?
C:\xampp\mysql\data
C:\xampp\php
C:\xampp\temp
C:\xampp\htdocs
What does the term "conditional control structure" mean?
A way to define a page’s CSS style.
A block of code that runs infinitely.
A system to connect to a database.
A mechanism to decide which block of code to execute based on a condition.
What does the acronym PHP mean?
Personal Home Page
Programming Hypertext Pages
Public Host Platform
Hypertext Preprocessor
Where is PHP code primarily executed?
In the client's browser (front-end)
In a MySQL database
On the server (back-end)
In a CSS file
What is the main function of PHP in web development?
Style web pages (CSS)
Create the static structure (HTML)
Create dynamic pages that interact with databases
Add interactivity on the client side (JavaScript)
Which opening and closing tags are used to delimit PHP code?
"
Which character must be used to declare a variable in PHP?
#
&
@
$ (dollar sign)
Which command is most common in PHP to print or display content (output) on a web page?
print()
display()
write()
echo
What does the semicolon (;) represent at the end of an instruction in PHP?
The start of a new code block
A separation between HTML and PHP
A line break in HTML
The end of an instruction or command
Which data type represents a value with decimal places (e.g., 3.14 ) in PHP?
Integers
Strings
Boolean
Floats
Which data type represents a true or false value in PHP?
Floats
Integers
Strings
Boolean
PHP code is generally embedded inside which other language?
JavaScript
SQL
CSS
HTML
Who was the initial creator of PHP in 1993, with the first version launched in 1995?
Linus Torvalds
Bill Gates
James Gosling
Rasmus Lerdorf
For the variable $cidade = "São Paulo";, what is the data type?
Integer
Float
Boolean
String
Which free software package that includes Apache, MySQL, and PHP is recommended to simulate a local web server?
WAMP
LAMP
MAMP
XAMPP
Which data type would represent a person's age (e.g., 25 ) in PHP?
Floats
Strings
Boolean
Integers
What does the term "dynamic pages" mean in PHP?
Pages with many moving images
Pages that do not change
Pages that use only CSS
Pages that can interact with databases and respond differently depending on the user or content
In PHP, which operator is used for multiplication?
+
-
;
*
In the mathematical expression 2+2∗4 , what is the result, respecting the order of precedence (multiplication before addition)?
16
4
10
8
In PHP, which operator is used to concatenate (join) strings and variables?
&
+
#
Dot (.)
If nome= and sobrenome= , which code will display "Ana Silva" (with a space)?
echo nome+ sobrenome;
echo nome: sobrenome;
echo nome: sobrenome;
echo nome. sobrenome;
Which operator is used for division in PHP?
\
//
%
/
If numero=7 , which PHP expression calculates the triple, as in Lesson 3?
triplo= numero + 3;
triplo= numero - 3;
triplo= numero / 3;
triplo= numero * 3;
In PHP, the addition operation is performed by which operator?
x
**
-
+
What does Lesson 3 emphasize about the precedence of operations in mathematical calculations in PHP?
All operations have the same priority.
Addition always has priority over multiplication.
PHP ignores the order of precedence.
Multiplication and division have priority over addition and subtraction.
If var1=10 and var2=5 , what is the result of var1−var2 ?
15
50
15
5
What is the result of echo "O valor total é " . 50 . " reais"; ?
O valor total é 50+reais
Syntax error
O valor total é 50
O valor total é 50 reais
What is the main benefit of concatenation in PHP?
Increase code security.
Reduce memory usage.
Perform complex calculations.
Display dynamic information in a readable, formatted way on the screen.
Which operator calculates the remainder of division between two numbers (modulo)?
/
*
#
%
If a=20 and b=3 , what will be the result of a%b ?
6.66
20
6
2
When concatenating a numeric variable with a string, PHP will:
Generate a type error.
Convert the string to a number.
Ignore the number.
Temporarily convert the number to a string to perform the concatenation.
XAMPP is a free software package that includes which essential resources to run PHP?
Windows, Apache, MySQL, Photoshop
Linux, Apache, MySQL, Perl
Apache, MySQL, PHP, Perl
Apache, PostgreSQL, Python, Java
The elseif structure is used for what purpose in a conditional block?
Execute code after the else block.
Perform a repetition of code.
Check a second or more conditions if the first is false.
Insert data into the database.
In the example from Lesson 4, to check if a number is positive, which logical condition should be used?
$number <= 0
$number == 0
$number < 0
$number > 0
If the value of the variable numberis−5,whichblockofcodewillrunwhentheprogramusesif( number > 0), elseif ($number == 0), and else?
The if block.
The elseif block.
The else block (Negative).
No block.
The conditional control structure (if/else) is defined as a mechanism that executes a block of code only when a condition is:
True.
Equal to zero.
Not null.
False.
What is the correct syntax to check an intermediate condition in PHP?
else if ($condition)
else ($condition)
elseif ($condition)
else ife ($condition)
In the athlete age classification exercise, which age range corresponds to the classification "Teen Team"?
Age 18 or older.
Age under 6 years.
Age 6 to 12 years.
Age 13 to 17 years.
If an athlete is 5 years old, which classification will they receive according to the conditions from Lesson 4?
Child Team
Teen Team
Adult Team
Baby Team (under 6 years)
Which comparison operator means "not equal to" in PHP?
==
>=
<=
!= or <>
If a=10and b = 10, what is the result of the expression a== b?
False (false)
10
True (true)
20
What happens if the variable $number is 0 in the Positive/Negative/Zero test that uses elseif?
The if block ($number > 0) runs.
The else block runs.
The elseif block ($number == 0) runs.
It causes an error.
Including one PHP code file inside another is often done using which command?
echo
if
else
include or require
In the athlete classification exercise, if the age is 12, what will the classification be?
Adult Team
Teen Team
Baby Team
Child Team (6 to 12 years)
What does the programming term "best practices" mentioned in Lesson 4 suggest?
That saving examples is not necessary.
That HTML code is more important than PHP.
That you must memorize the code.
Follow the examples, practice, and take notes.
What does the condition if ( age < 18) mean in logical terms?
The age is less than 12 or greater than 18.
The age is less than or equal to 12.
The age is 12 or 18.
The age is between 13 and 17 (greater than 12 and less than 18).
In which form submission method are data transferred more securely (not appearing in the URL)?
GET
SESSION
COOKIE
POST
What is the name of the PHP superglobal array used to receive data from a form submitted by the POST method?
$_GET
$_SERVER
$_SESSION
$_POST
In the Lesson 5 flow, which page (PHP file) is responsible for receiving the data and performing the bonus calculation with if/else logic?
form3.php
index.html
conexao.php
resultado.php
What was the minimum sales value (condition) for the employee to receive a $500.00 bonus?
$5,000.00
$9,999.99
$10,000.00
$10,000.00
If sales are vendas=9500,whatwilltheiflogicif( vendas >= 10000) do?
The employee will receive the $500.00 bonus.
The variable $vendas will be updated.
An error message will be displayed.
The else block will run (message that the target was not reached).
In PHP, when receiving the sales field from a form, what is the correct syntax to store it in a variable $vendas?
vendas= _GET['vendas'];
vendas= _POST.vendas;
POST[′vendas′]= vendas;
vendas= _POST['vendas'];
What does Lesson 5 highlight about the importance of using forms in web development?
They are used only for design purposes.
They are used only to send emails.
They serve only to test CSS.
They allow collecting user information for processing and dynamic interaction.
In the form (form3.php), the action attribute is used to:
Define the field type.
Define the submission method.
Define the field name.
Indicate which page the data will be sent to (e.g., resultado.php).
Which code snippet is used to allow the user to return to the form from the resultado.php page?
For which form field was the variable $setor used to receive the value?
Name
Sales
Bonus
Department
What main resource does the code echo "Hello Employee name,department: setor, see your Bonus:
" use?
Conditional structures.
File manipulation.
Mathematical operations.
Concatenation and displaying variables.
If the form’s method attribute is omitted, by which method will data be sent by default?
GET
POST
SESSION
PUT
Which of the following is not a PHP superglobal?
$_POST
$_GET
$_SESSION
$_ARRAY
On the resultado.php page, the variable $vendas receives the form value. Which line of code displays the value of this variable?
if ($vendas >= 10000)
vendas= _POST['vendas'];
echo "You will receive a bonus...";
echo $vendas; (when used outside the main string).
In the Lesson 5 form, what is the purpose of the name attribute in an HTML input?
Define the visual style.
Define the data type.
Determine the submission method.
Identify the field so PHP can receive it via $_POST['name'].
What is the main objective of Lesson 6?
Connect to and query a database.
Send automatic emails.
Create interactive charts.
Collect form data and save it to a .txt file.
The native PHP function file_put_contents() is used to:
Only read the content of a file.
Only open a file for writing.
Move a file to a folder.
Create a text file and write content to it.
In the file-writing flow, which function is used to generate a date and time string to create unique file names (for example: dados_20250506_150102.txt)?
time()
unique_id()
datetime()
date("Ymd_His")
Which condition is used on the processing page (dados.php in Lesson 6) to ensure the code only runs if the form was sent via POST?
$_POST["name"] != ""
if(isset($_POST))
if($conteudo != "")
$_SERVER["REQUEST_METHOD"] == "POST"
In the code that processes data for a .txt file, which structure is used to loop through the $_POST array and extract the field name and the typed value?
for
while
if
foreach
What does the concatenation \n represent inside the content string that will be written to the .txt file?
A tab (large space).
The end of the file.
A division bar.
A line break.
In Lesson 6, what is the variable $conteudo responsible for?
Storing the file name.
Defining the HTML structure of the page.
Storing the database connection data.
Concatenating all form information into a single string that will be written to the file.
Why is it important to use a function like date("Ymd_His") to name the generated text files?
To define the file type.
To encrypt the file.
So PHP can read the file.
To prevent new submissions from overwriting old files, ensuring uniqueness.
When looping through POSTwithforeach,whatdoesthevariable chave (field name) store?
The value typed by the user.
The .txt file name.
The date and time.
The name attribute of the form field.
If the validation $_SERVER["REQUEST_METHOD"] == "POST" fails, what does the page display?
The form page again.
A 404 error.
A success message.
"Invalid access."
Where will the .txt files created by the PHP script (Lesson 6) be saved in XAMPP if the code does not specify a different path?
In the folder C:\\xampp\\temp.
In the folder C:\\xampp\\mysql.
In the root of drive C:.
In the same folder where the PHP file (dados.php in Lesson 6) is located.
What does the code snippet $_POST["campo"] ?? "" do in the Lesson 6 code?
Sets the default value to 0.
Forces the field to have a value.
Ensures that if the field does not exist in $_POST, no error occurs (Null Coalescing Operator).
Validates whether the field is a number.
What is the role of the file form6.php in Lesson 6?
Create the .txt file.
Process the data.
List the created files.
Contain the HTML form for collecting data.
What must be done in the browser so the form-processing page (like dados.php in Lesson 6) can be tested correctly?
Access it directly by its address.
Restart XAMPP.
Open the .txt file.
Fill out the form in form6.php and click the "Submit" button.
What does the function date("His") return?
The full year.
The current date (day, month, year).
Hour, minute, and second.
The name of the month.
What is the main purpose of a database connection in PHP, as in Lesson 7?
To style web pages.
To only read data from .txt files.
To run code on the client side.
To allow the PHP script to communicate with the database to store, query, update, or delete data.
In the Lesson 7 connection flow, which PHP file has the exclusive role of opening the communication channel with the database server (MySQL/MariaDB)?
index.php
validar.php
dados.php
conexao.php
What is the name of the graphical tool (included in XAMPP) used to manage the database (create tables, insert records manually, etc.)?
MySQL Workbench
SQL Server
HeidiSQL
phpMyAdmin
When creating the usuarios table in phpMyAdmin, which two properties are essential for the ID field (record identifier)?
Type VARCHAR and NOT NULL.
Type FLOAT and Default 0.
Type TEXT and UNIQUE.
Primary Key (PRIMARY KEY) and Auto Increment (A_I or Auto Increment).
In the registration flow, which page (PHP file) is responsible for receiving form data and executing the SQL INSERT INTO instruction to save the information to the database?
index.php
conexao.php
dados.php
validar.php
Which SQL instruction is used on the page validar.php (Lesson 7) to add a new record to the usuarios table?
UPDATE
SELECT
DELETE
INSERT INTO
In which file is the PHP function mysqli_connect() used?
validar.php
index.php
dados.php
conexao.php
If the database is named cadastros and the server is on your local machine, what is the host name used in the connection?
192.168.1.1
db_server
localhost/cadastros
localhost (or 127.0.0.1)
Which of the following fields was not used in the usuarios table created in Lesson 7?
ID
usuario
senha
cpf
After registration in validar.php, which message is displayed to the user (indicating success of the operation)?
"Server error!"
"Invalid Access!"
"Registration completed successfully!"
"Back"
What happens to the ID of a new record in the usuarios table thanks to the Auto Increment (A_I) property?
The user must type it in the form.
It will always be 1.
It is generated automatically by the database, increasing with each new record.
It is an optional field that may be left blank.
What does the command mysqli_query() do in the context of validar.php?
Receives form data.
Opens the database connection.
Closes the database connection.
Executes the SQL instruction (INSERT INTO...) on the database.
What term is used for the process that allows the PHP script to send SQL commands and receive results?
Authentication
Loop (repetition)
Conditional structure
Communication channel / Database connection
Which DBMS (Database Management System) used in the lessons is part of XAMPP?
PostgreSQL
Oracle
SQL Server
MySQL/MariaDB
Why is it important to include the file conexao.php at the beginning of validar.php?
To define the page style.
So the form variables can be read.
So the database connection is active before attempting to execute INSERT INTO.
To include the HTML menu.
The page dados.php (Lesson 8) is the main example of which CRUD operation?
Create
Update
Read
Delete
What does the acronym CRUD represent in system development?
Clean, Read, Update, Deploy
Connect, Run, Upload, Download
Client, Router, User, Data
Create, Read, Update, Delete
Which SQL instruction is used on the page dados.php to select and list all registered users?
UPDATE
DELETE
INSERT INTO
SELECT * FROM usuarios
Which PHP function is used on the page dados.php (inside a while loop) to iterate through and return each row of the SQL query result as an associative array?
mysqli_connect()
mysqli_query()
mysqli_num_rows()
mysqli_fetch_assoc()
The function mysqli_num_rows() is used to:
Close the connection to the database.
Execute the SQL query.
Return the first row of the result.
Check if there are more than zero rows (records) returned by the query.
Why does the page dados.php use a while loop?
To define the CSS style.
To insert new data.
To close the connection.
To iterate over the set of query results and display each record in the table.
If the SQL query does not return any records, what will the else block of dados.php display?
A connection error.
An empty table.
A syntax error.
"No user registered."
How are the data from each field (e.g., usuario) displayed in the HTML table inside the while loop?
Using $_POST["usuario"]
Using echo $usuario
Using mysqli_query("SELECT usuario")
Using echo linha[′usuario′](where linha is the associative array)
Which PHP file must be included in dados.php before performing the database query?
index.php
validar.php
conexao.php
style.css
The
c) d) 116. What does the command resultado=mysqliquery( conexao, $sql); do? a) Starts the server. b) Defines the connection. c) Stores the SQL instruction in the variable $sql. d) Executes the SQL query and stores the result in $resultado. 117. The variable $linha (returned by mysqli_fetch_assoc()) contains the record data in which format? a) A single string with all data. b) A PHP object. c) Only the user's ID. d) An associative array (where the key is the column name, e.g., usuario). 118. What does the code display in the table on the page dados.php? a) The field name "id". b) The static text "id". c) The unique identification number of each user. d) The table name. 119. The final goal of Lessons 7, 8, and 9 is to have a complete system that allows you to: a) Only register data. b) Only display the home page. c) Only handle text files. d) Perform the four CRUD operations (Create, Read, Update, and Delete). 120. The page editar.php (Lesson 9) implements which CRUD operation? a) Create b) Read c) Delete d) Update 121. The page excluir.php (Lesson 9) implements which CRUD operation? a) Create b) Read c) Update d) Delete 122. Which SQL instruction does the page excluir.php use to remove a record from the database? a) SELECT * FROM usuarios WHERE ID = X b) UPDATE usuarios SET... WHERE ID = X c) INSERT INTO usuarios VALUES... d) DELETE FROM usuarios WHERE ID = X 123. How do the pages editar.php and excluir.php identify the specific user record that must be modified or removed? a) By the user's full name. b) By the user's email. c) By the password. d) By the field ID of the record. 124. On the page editar.php, the form field is pre-filled with the user's current data for editing. Which HTML attribute, together with PHP echo, is used to display the current value of the field? a) placeholder b) name c) id d) value 125. Before displaying the edit form on editar.php, which SQL operation is performed first? a) UPDATE to clear the fields. b) INSERT to duplicate the record. c) DELETE to remove the old record. d) SELECT * FROM usuarios WHERE ID = X to fetch the user's current data. 126. The SQL instruction to update a record (UPDATE) is executed in which part of the page editar.php? a) On the first time the page loads. b) When the page is deleted. c) After the user fills in the form and clicks the "Update" button (sent via POST). d) Only when closing the connection. 127. Which SQL instruction is used to modify the data of an existing record (Update)? a) CREATE TABLE b) SELECT c) INSERT INTO d) UPDATE usuarios SET campo='novo_valor' WHERE ID = x 128. Which submission method (GET or POST) is most likely used on the page dados.php to send the user's ID to excluir.php or editar.php through a link? a) POST b) SESSION c) COOKIE d) GET (e.g., excluir.php?id=10) 129. What happens to a user when they click the "Delete" link and the action is processed by excluir.php? a) The record is marked as inactive. b) The user is redirected to the home page. c) The user's data are sent to a .txt file. d) The user's record is permanently removed from the database. 130. The page editar.php uses the superglobal array $_POST (after the form is submitted) to receive what? a) Only the user's ID. b) Only the password. c) The new values for username, email, and password. d) The SQL SELECT command. 131. What does Lesson 9 highlight as the final result of all the learning? a) Knowing only basic PHP syntax. b) Creating only static forms. c) Manipulating only text files. d) Having a website with a database and the functionalities to Create, Read, Update, and Delete (CRUD). 132. What is the role of the "Cancel" button on the page editar.php? a) Delete the record from the database. b) Confirm the deletion. c) Redirect back to the page dados.php without making changes. d) Send the form data. 133. Which PHP function is used in excluir.php to execute the DELETE FROM... instruction on the database? a) mysqli_fetch_assoc() b) mysqli_connect() c) mysqli_close() d) mysqli_query() 134. What must be included in the code of editar.php and excluir.php to ensure the operation can be performed? a) style.css b) index.php c) validar.php d) conexao.php 100 % Similar Resources on Wayground129 questions Đề cương ôn tập Tin học – Trắc nghiệm MS Word Worksheet • University 136 questions IAS_REVIEWER Worksheet • University 133 questions АКТ Сессия 1курс 126-250 Worksheet • University 133 questions Trắc nghiệm CS 226 Worksheet • University 130 questions Triết học Mác - Lênin Bài 1-9 Full Đ/S và Kéo thả Worksheet • University |
