
Q1
Q1 Which of the following is a correct way to define a constant in PHP?
define('CONST_NAME', 'Value');
const CONST_NAME = 'Value';
Both a and b
None of the above
Q2
Q2 What will be the output of the following PHP code?
6
123
Error
1
Q3
Q3 Which of the following data types is not supported in PHP?
String
Array
Object
Character
Q4
Q4 What will be the output of the following PHP code?
$x = "Hello";
$y = 'World';
echo $x . " " . $y;
?>
HelloWorld
Hello World
Hello+World
Error
Q5
Q5 Consider the PHP array:
$arr = array(1, 2, 3, 4);
What is the correct way to access the third element?
$arr[2]
$arr[3]
$arr[2]
$arr(3)
Q6
Q6 Identify the error in this PHP code snippet:
Missing semicolon
Syntax error in echo
Variable declaration error
No error in the code
Q7
Q7 Spot the error in the following PHP code:
for ($i = 0; $i <= 10; $i++) {
echo $i; } echo $i;
?>
Undefined variable outside loop
Missing semicolon
No error in the code
Syntax error in loop
Q8
Q8 What method should be used to send sensitive data in a form?
GET
POST
PUT
DELETE
Q9
Q9 Which superglobal array in PHP contains information about headers, paths, and script locations?
$_GET
$_POST
$_SERVER
$_FILES
Q10
Q10 In a form, to group multiple elements that belong together, which HTML tag is used?
Q11
Q11 How do you access form data sent via the GET method in PHP?
Using the $_REQUEST superglobal
Using the $_GET superglobal
Using the $_POST superglobal
Using the $_SERVER superglobal
Q12
Q12 What is the correct way to check if a form has been submitted in PHP?
Checking if $_POST is set
Checking if $_GET is set
Checking if $_SERVER['REQUEST_METHOD'] is POST
Checking if $_REQUEST is set
Q13
Q13 Which attribute in a form input element specifies the field's initial value?
value
type
name
placeholder
Q14
Q14 Given a form with method="post", which PHP array will contain the form's submitted data?
$_GET
$_POST
$_REQUEST
$_SERVER
Q15
Q15 What will be the output of the following PHP code if a user submits a form with an input named email?
if (isset($_POST['email'])) {
echo $_POST['email'];
}
?>
The value of the email input field
NULL
An empty string
An error message
Q16
Q16 In PHP, how do you securely access a form value sent via POST to prevent XSS attacks?
Using htmlspecialchars($_POST['value'])
Using $_POST['value'] directly
Using strip_tags($_POST['value'])
Using mysqli_real_escape_string($_POST['value'])
Q17
Q17 Identify the issue in this PHP code for handling a form input:
if (isset($_GET['submit'])) {
echo $_POST['name'];
}
?>
Incorrect use of $_GET and $_POST
No issue
Syntax error
The input name should be 'submit' instead of 'name'
Q18
Q18 Spot the error in the following PHP form handling code:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo $_POST[name];
}
?>
Missing quotes around array key name
No error in the code
Syntax error in if statement
Missing semicolon in echo statement
Q19
Q19 Which PHP function is used to connect to a MySQL database?
mysql_connect()
mysqli_connect()
connect_db()
db_connect()
Q20
Q20 In PHP, which function is used to execute a SQL query against a MySQL database?
mysql_query()
mysqli_query()
execute_sql()
run_query()
Q21
Q21 When retrieving data from a MySQL database, which PHP function is used to fetch a row as an associative array?
mysqli_fetch_assoc()
mysqli_fetch_array()
mysqli_fetch_row()
mysqli_fetch_all()
Q22
Q22 What does the PHP mysqli_real_escape_string() function do?
Sanitizes input for use in a SQL query
Converts special characters to HTML entities
Encrypts a string
Splits a string into an array
Q23
Q23 Which of the following is an appropriate use of PHP Data Objects (PDO)?
Connecting to multiple database types
Creating HTML content
Parsing JSON data
Managing PHP sessions
Q24
Q24 What is the main advantage of using prepared statements in PHP for database queries?
Increased query execution speed
Reduced memory usage
Enhanced security against SQL injection attacks
Simplified syntax
Q25
Q25 What does the connect_errno property of a mysqli object indicate in PHP?
It indicates the error number of the last connection attempt
It returns the total number of failed connection attempts
It is a boolean value indicating whether the connection was successful
It stores the MySQL server version
Q26
Q26 Consider the PHP code:
$stmt = $mysqli->prepare("SELECT * FROM users WHERE id = ?");
$stmt->bind_param("i", $id);
What does the "i" in bind_param() signify?
Integer data type
Incremental value
Input parameter
Invalid parameter
Q27
Q27 In a PHP script using MySQLi, what does the close() method do when applied to a mysqli object?
Closes the database connection
Saves changes to the database
Closes the PHP script
Resets all variables in the script
Q28
Q28 Identify the error in the following PHP code:
$mysqli = new mysqli("localhost", "user", "password", "database"); $result = $mysqli->query("SELECT * FROM users WHERE id = '$id'");
No error in the code
Missing database connection error handling
Improper string concatenation in the query
SQL injection vulnerability
Q29
Q29 Spot the error in this PHP database connection code:
$mysqli = new mysqli("localhost", "user", "password"); $mysqli->select_db("database");
Missing database in the constructor
Improper method to select a database
No error in the code
Syntax error in mysqli instantiation
Q30
Q30 Which PHP statement is used to execute the same code a specified number of times?
foreach
while
for
do-while

