PHP Programming MCQ Quiz: Exam!

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Nishthat7ec
N
Nishthat7ec
Community Contributor
Quizzes Created: 2 | Total Attempts: 380,615
| Attempts: 292 | Questions: 40
Please wait...
Question 1 / 40
0 %
0/100
Score 0/100
1. The following 2 lines are part of a HTML document, fill in the blank:  

Explanation

The correct answer is "form, FORM, Form" because the HTML element for creating a form is written as "form" in lowercase. However, HTML is case-insensitive, so "FORM" and "Form" are also valid alternatives for the same element.

Submit
Please wait...
About This Quiz
PHP Programming MCQ Quiz: Exam! - Quiz

This PHP Programming MCQ Quiz assesses key skills in managing data interactions in web development using PHP. It covers database connections, form data retrieval, and SQL queries, providing... see morea practical evaluation for learners aiming to enhance their PHP programming capabilities. see less

2. The three blanks in the code have the same answer:


The missing code is :

Explanation

The missing code, "=>", is an arrow function syntax in JavaScript. It is used to define anonymous functions in a more concise way. The arrow function allows for implicit return of a single expression, making the code shorter and easier to read. It is commonly used in functional programming and is especially useful when working with arrays and higher-order functions like map, filter, and reduce.

Submit
3. The ‘c203project’ database has a table called ‘keyContacts’, with the following schema:


What is the primary key field name?

Explanation

The primary key field name in the 'keyContacts' table of the 'c203project' database can be any of the three options: contact_id, CONTACT_ID, or contact_ID. The primary key field is used to uniquely identify each record in the table, and it must have a unique value for each row. The case sensitivity of the field name depends on the database system being used.

Submit
4. The following lines are part of a HTML document for login screen:



Fill in the blank so that user will not see the password being typed in:

Explanation

The given lines of code are different variations of the word "password" in HTML. By using different cases (lowercase, uppercase, and capitalized), it ensures that the user's password is not visible while they are typing it in. This is a security measure to protect the user's password from being easily seen by others.

Submit
5. Complete the code according to comment provided:

Explanation

not-available-via-ai

Submit
6. How many mandatory arguments (parameters) does fopen() function require?

Explanation

The fopen() function requires two mandatory arguments (parameters) to be passed. These arguments specify the file name and the mode in which the file should be opened. The function cannot be called without providing these two arguments.

Submit
7. What is the name of the PHP code that is executed when the Calculate button of this form is pressed?


Answer:

Explanation

The PHP code that is executed when the Calculate button of the form is pressed is called "trainSvc.php".

Submit
8. The following lines are part of a PHP code to retrieve session information for an authenticated user; complete the code according to comment provided:

Explanation

The "isset" function in PHP is used to check if a variable has been set and is not null. In the given context, the "isset" function is being used to check if the session information for an authenticated user exists. This is important because if the session information is not set, it means that the user is not authenticated and the code can handle the situation accordingly.

Submit
9. The following lines are part of a PHP code to register new user into a database; complete the code according to comment provided:

Explanation

The given code is using the sha1() function in PHP to encrypt the password before storing it in the database. The sha1() function calculates the SHA-1 hash of a string. In this case, the variable $passw is being passed as the parameter to the sha1() function. The code is providing different variations of passing the parameter, including with and without spaces before or after the variable. All of these variations will work and produce the same result.

Submit
10. Retrieve data from a FORM with an input named 'distance' that is submitted using the "post" method. Write ONE PHP statement to store the data in variable $gap.

Explanation

The correct answer is any of the given options: $gap = $_POST['distance'];, $gap = $_POST['distance'], $gap = $_POST ['distance'] ;, $gap=$_POST['distance'];, $gap=$_POST["distance"]. These options all show the correct way to retrieve data from a form with an input named 'distance' that is submitted using the 'post' method and store it in the variable $gap.

Submit
11. Rearrange these steps in the correct order. 1. Connect to Database Server 2. Close database connection 3. Execute SQL query 4. Retrieve HTML form data 5. Build SQL statement

Explanation

The correct order of the steps is as follows:
1. Connect to Database Server
2. Retrieve HTML form data
3. Build SQL statement
4. Execute SQL query
5. Close database connection

First, we need to establish a connection to the database server. Then, we retrieve the data entered in the HTML form. Next, we build the SQL statement using the retrieved data. After that, we execute the SQL query to perform the desired action on the database. Finally, we close the database connection to free up resources.

Submit
12. Examine the loop below and write down the value of $y printed on the screen.

Value of $y:

Explanation

not-available-via-ai

Submit
13. What is the return type of strcmp() function?

Explanation

The return type of the strcmp() function is int. This function is used to compare two strings and returns an integer value indicating the relationship between the strings. If the return value is less than 0, it means the first string is less than the second. If the return value is greater than 0, it means the first string is greater than the second. And if the return value is 0, it means the strings are equal.

Submit
14. The following lines are part of a PHP code to authenticate user; complete the code according to comment provided:

Explanation

The correct answer is to use "session_start()" to start a new or resume an existing session. The other two options, "session_start ( )" and "session_start ()", are incorrect because they include unnecessary spaces within the parentheses, which would result in a syntax error in PHP.

Submit
15. In a numerically indexed array, what is the index number to access the 2nd item?

Explanation

The index number to access the 2nd item in a numerically indexed array is 1. In programming, arrays are typically zero-based, meaning that the first item is accessed using an index of 0. Therefore, the second item would be accessed using an index of 1.

Submit
16. Complete the while-loop that terminates (stops) when $myData reaches 33 (not inclusive).

Explanation

The correct answer is the condition of the while-loop, which states that the loop will continue as long as $myData is less than 33. This means that the loop will stop executing when $myData reaches 33, but not include that value. The other options are not relevant to the termination of the loop.

Submit
17. Complete the code according to comment provided:

Answer:

Explanation

not-available-via-ai

Submit
18. The following lines are part of a PHP code to set session information for an authenticated user; complete the code according to comment provided:

Explanation

not-available-via-ai

Submit
19. The following 2 lines are part of a HTML document, fill in the blank:

code for FIB 

Explanation

The given answer includes the correct syntax for the HTML tag "submit". In HTML, tags are case-insensitive, so "submit" and "Submit" are both valid. However, "SUBMIT" is not a valid tag in HTML as tags are typically written in lowercase.

Submit
20. Examine the loop below and write down the value of $x printed on the screen.

Value of $x:

Explanation

not-available-via-ai

Submit
21. Complete the PHP statement to retrieve data from a FORM with an input named 'weight' that is submitted using the "post" method. $myData = __________ ;

Explanation

The correct answer is $_POST['weight'], $_POST["weight"], $_POST ['weight'], $_POST ["weight"]. These are all valid ways to retrieve data from a form with an input named 'weight' that is submitted using the 'post' method in PHP. The $_POST superglobal variable is used to access form data that is submitted using the 'post' method, and the input name is used as the key to retrieve the value. The different variations of the input name syntax (with or without spaces and quotes) are all acceptable in PHP.

Submit
22. The following lines are part of a PHP code to retrieve information from database; complete the code according to comment provided:

Explanation

The given answer suggests that any of the four options provided can be used to retrieve the value of the "contact_name" field from the $record array in PHP. The options include using single quotes, double quotes, or a combination of both to access the array element. All of these options are valid in PHP and will give the same result.

Submit
23. What is the required data type of the first argument (parameter) of fopen() function?

Explanation

The required data type of the first argument (parameter) of the fopen() function can be any of the options provided: string, STRING, str, STR, or String. The function fopen() is used to open a file and the first argument specifies the name of the file to be opened. In programming, the term "string" is commonly used to represent a sequence of characters, so any of the provided options can be used as the data type for the first argument of the fopen() function.

Submit
24. The following 2 lines are part of a HTML document , fill in the blank:

Explanation

The "enctype" attribute is used in HTML forms to specify how the form data should be encoded and sent to the server. It is a required attribute when the form contains file upload fields. The "enctype" attribute can have different values such as "application/x-www-form-urlencoded" (default value), "multipart/form-data", or "text/plain". The value "enctype" is used to specify the encoding type for the form data.

Submit
25. The following lines are part of a PHP code to retrieve information from database; complete the code according to comment provided:

Explanation

The given answer provides the correct way to access the value at index 2 of the $rowData array in PHP. In PHP, array indices are case-sensitive, so $rowData [2] and $rowData[2] are both valid ways to access the value. Additionally, whitespace characters are allowed between the variable name and the index, so $rowData [2 ] and $rowData[2 ] are also valid ways to access the value.

Submit
26. Choose the most appropriate statement that will check for the successful execution of a SELECT SQL query.

Explanation

The correct answer is the if statement "if (mysqli_query($link, "SELECT * FROM keyContacts"))". This statement checks if the SELECT SQL query "SELECT * FROM keyContacts" is successfully executed using the mysqli_query() function. If the query is successful, the if statement will evaluate to true and the code inside the if block will be executed.

Submit
27. The ‘c203project’ database has a table called ‘keyContacts’, with the following schema:


Complete the PHP statement to store the SQL statement in variable $queryCount - Find out total number of contacts.
___________________________________________  FROM keyContacts";

Explanation

The correct answer is "$queryCount = "SELECT COUNT(contact_id)". This is the correct PHP statement to store the SQL statement in the variable $queryCount. It uses the COUNT() function in SQL to find the total number of contacts in the 'keyContacts' table.

Submit
28. Which function will get a result row as a numerically indexed array after the successful execution of a SELECT SQL query?

Explanation

The function mysqli_fetch_row($allRows) will retrieve a result row as a numerically indexed array after the successful execution of a SELECT SQL query.

Submit
29. What is the result of execution of a failed INSERT SQL query?

Explanation

When a failed INSERT SQL query is executed, it means that the query was not successful in inserting the data into the database. In this case, the result of the execution would be False, indicating that the query did not successfully insert the data.

Submit
30. Complete the PHP statement to execute the SQL query in variable $selectStr. Database connection is stored in variable $conn.
$allRows = ______________________________;

Explanation

Do not add the die() function in the statement.

Submit
31. The following lines are part of a PHP code to authenticate user; complete the code according to comment provided:

Explanation

not-available-via-ai

Submit
32. What is the result of execution of a successful SELECT SQL query?

Explanation

A successful SELECT SQL query typically returns a result object. This result object contains the data that matches the query criteria and can be further manipulated or displayed as needed. It allows the user to access and retrieve the desired information from the database.

Submit
33. Complete the PHP statement to retrieve data from a FORM with an input named ‘durationInHour’ that is submitted using the “post” method; convert it to seconds.
$ durationInSeconds = $_POST['_______________;

Explanation

The correct answer is `durationInHour' ] * 3600`. This is because the statement is using the `$_POST` superglobal to retrieve the value submitted from the form input named 'durationInHour'. The value is then multiplied by 3600 to convert it to seconds and assigned to the variable `$durationInSeconds`.

Submit
34. The following lines are part of a PHP code to retrieve information from database; the result of execution of a successful SELECT SQL query is stored in a variable $allRows:


Fill in the blank:

Explanation

The correct answer is mysqli_fetch_array($allRows), mysqli_fetch_row($allRows), mysqli_fetch_array ($allRows), mysqli_fetch_row ($allRows), mysqli_fetch_row($allRows). These are all valid functions in PHP for retrieving rows from a MySQL database. mysqli_fetch_array() returns a row as an associative array, a numeric array, or both. mysqli_fetch_row() returns a row as a numeric array. Both functions can be used to iterate through the result set obtained from a SELECT SQL query.

Submit
35. Consider the following scenario and answer the related questions: • XAMPP is in the c:\xampp\ folder of your local machine • The c:\xampp\htdocs\myProject\ folder contains a HTML document called postItem.html What is the URL to display postItem.html in your browser in the same machine? ____________________________________________________

Explanation

The correct answer is http://localhost/myProject/postItem.html. This is because the URL to access a file on a local machine typically starts with "http://localhost/" followed by the file path relative to the web server's document root. In this case, the document root is the "htdocs" folder within the XAMPP installation directory, and the file "postItem.html" is located within the "myProject" subfolder of the document root. Therefore, the correct URL to access the file in the browser is "http://localhost/myProject/postItem.html".

Submit
36. Complete the for-loop that prints all multiples of 3 between 10 and 51 (both inclusive), in descending order (that is, starting from 51). 
 

Explanation

The correct answer is $i % 3 == 0, $i%3==0, $i % 3 == 0. These three options are all valid syntax to check if a number is divisible by 3 using the modulo operator. The modulo operator returns the remainder when one number is divided by another. In this case, we want to check if $i is divisible by 3, so if the remainder is 0, it means $i is a multiple of 3.

Submit
37. The ‘c203project’ database has a table called ‘keyContacts’, with the following schema:


Complete the PHP statement to store the SQL statement in variable $query1 - Inserting ONE record into the table. _________________________ (contact_name, phone, email) VALUES ($name, $contactno, $eMail)";

Explanation

not-available-via-ai

Submit
38. The ‘c203project’ database has a table called ‘keyContacts’, with the following schema:


Complete the PHP statement to store the SQL statement in a string variable that will List out the name of all contacts with email containing “rp.sg” at the end.
$querySel = "SELECT contact_name _______________________________ ;

Explanation

The correct answer is "FROM keyContacts WHERE email LIKE '%rp.sg'". This statement correctly completes the PHP code to store the SQL statement in a string variable. The SELECT keyword is used to specify the columns to be retrieved, and the FROM keyword is used to specify the table to retrieve the data from. The WHERE clause is used to filter the results based on the condition specified, which in this case is to retrieve contacts with email containing "rp.sg" at the end. The LIKE keyword is used for pattern matching, and the % symbol is a wildcard that matches any characters.

Submit
39. The ‘c203project’ database is residing in server “sit.rp.sg”; it has a table called ‘keyContacts’. Complete the PHP statement to connect to the MySQL Server using user “admin” with password “pWd!”.
$conn = __________________________________________________;

Explanation

Do not add the die() function in the statement.

Submit
40. Write ONE PHP statement to show this output using variable $gap (need to pay attention to spacing in the output):

Explanation

The given answer is correct because it demonstrates the correct syntax for concatenating the string "Gap: " with the value of the variable $gap and the string " cm" using the dot (.) operator. This ensures that the output will display the value of $gap with the appropriate spacing and units.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jun 04, 2015
    Quiz Created by
    Nishthat7ec
Cancel
  • All
    All (40)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
The following 2 lines are part of a HTML document, fill in the blank:...
The three blanks in the code have the same answer: The missing code is...
The ‘c203project’ database has a table called ‘keyContacts’,...
The following lines are part of a HTML document for login screen:Fill...
Complete the code according to comment provided:
How many mandatory arguments (parameters) does fopen() function...
What is the name of the PHP code that is executed when the Calculate...
The following lines are part of a PHP code to retrieve session...
The following lines are part of a PHP code to register new user into a...
Retrieve data from a FORM with an input named 'distance' that is...
Rearrange these steps in the correct order. ...
Examine the loop below and write down the value of $y printed on the...
What is the return type of strcmp() function?
The following lines are part of a PHP code to authenticate user;...
In a numerically indexed array, what is the index number to access the...
Complete the while-loop that terminates (stops) when $myData reaches...
Complete the code according to comment provided: Answer:
The following lines are part of a PHP code to set session information...
The following 2 lines are part of a HTML document, fill in the...
Examine the loop below and write down the value of $x printed on the...
Complete the PHP statement to retrieve data from a FORM with an input...
The following lines are part of a PHP code to retrieve information...
What is the required data type of the first argument (parameter) of...
The following 2 lines are part of a HTML document , fill in the blank:
The following lines are part of a PHP code to retrieve information...
Choose the most appropriate statement that will check for the...
The ‘c203project’ database has a table called ‘keyContacts’,...
Which function will get a result row as a numerically indexed array...
What is the result of execution of a failed INSERT SQL query?
Complete the PHP statement to execute the SQL query in variable...
The following lines are part of a PHP code to authenticate user;...
What is the result of execution of a successful SELECT SQL query?
Complete the PHP statement to retrieve data from a FORM with an input...
The following lines are part of a PHP code to retrieve information...
Consider the following scenario and answer the related questions:...
Complete the for-loop that prints all multiples of 3 between 10 and 51...
The ‘c203project’ database has a table called ‘keyContacts’,...
The ‘c203project’ database has a table called ‘keyContacts’,...
The ‘c203project’ database is residing in server “sit.rp.sg”;...
Write ONE PHP statement to show this output using variable $gap (need...
Alert!

Advertisement