1.
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
Correct Answer
D. 1,4,5,3,2
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.
2.
Complete the pHP statement to retrieve data from a FORM with an input named ‘weight’ that is submitted using the “post” method.
$myData = __________ ;
Correct Answer
$_POST['weight']
$_POST["weight"]
$_POST ['weight']
$_POST ["weight"]
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.
3.
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?
____________________________________________________
Correct Answer
http://localhost/myProject/postItem.html/
http://localhost/myProject/postItem.html
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".
4.
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.
Correct Answer
$gap = $_POST['distance'];
$gap = $_POST['distance']
$gap = $_POST ['distance'] ;
$gap=$_POST['distance'];
$gap=$_POST["distance"];
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.
5.
The following 2 lines are part of a HTML document, fill in the blank:
Correct Answer
submit
SUBMIT
Submit
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.
6.
The following 2 lines are part of a HTML document, fill in the blank:
Correct Answer
form
FORM
Form
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.
7.
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:
Correct Answer
password
PASSWORD
Password
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.
8.
Write ONE pHP statement to show this output using variable $gap (need to pay attention to spacing in the output):
Correct Answer
echo 'Gap: ' . $gap . ' cm
';
echo "Gap: " . $gap . " cm
";
echo 'Gap: '.$gap.' cm
';
echo "Gap: ".$gap." cm
";
echo "Gap: ".$gap." cm
" ;
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.
9.
Complete the for-loop that prints all multiples of 3 between 10 and 51 (both inclusive), in descending order (that is, starting from 51).
Correct Answer
$i%3 == 0
$i%3==0
$i % 3 == 0
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.
10.
Complete the while-loop that terminates (stops) when $myData reaches 33 (not inclusive).
Correct Answer
$myData < 33
$myData<33
$myData <= 32
$myData<=32
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.
11.
Examine the loop below and write down the value of $x printed on the screen.Value of $x:
Correct Answer
33
12.
Examine the loop below and write down the value of $y printed on the screen.Value of $y:
Correct Answer
34
13.
What is the return type of strcmp() function?
Correct Answer
int
integer
INT
Integer
INTEGER
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.
14.
How many mandatory arguments (parameters) does fopen() function require?
Correct Answer
2
TWO
two
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.
15.
What is the required data type of the first argument (parameter) of fopen() function?
Correct Answer
string
STRING
str
STR
String
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.
16.
What is the name of the pHP code that is executed when the Calculate button of this form is pressed?Answer:
Correct Answer
trainSvc.php
Explanation
The PHP code that is executed when the Calculate button of the form is pressed is called "trainSvc.php".
17.
Complete the code according to comment provided: Answer:
Correct Answer
$cnter
18.
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['_______________;
Correct Answer
durationInHour'] * 3600
durationInHour']*3600
durationInHour' ] * 3600
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`.
19.
The ‘c203project’ database has a table called ‘keyContacts’, with the following schema:What is the primary key field name?
Correct Answer
contact_id
CONTACT_ID
contact_ID
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.
20.
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)";
Correct Answer
$query1 = "INSERT INTO keyContacts
$query1="INSERT INTO keyContacts
$query1 = "insert into keyContacts
$query1="insert into keyContacts
$query1= "INSERT INTO keyContacts
21.
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";
Correct Answer
$queryCount = "SELECT COUNT(contact_id)
$queryCount= "SELECT COUNT(contact_id)
$queryCount ="SELECT COUNT(contact_id)
$queryCount ="SELECT COUNT(*)
$queryCount = "SELECT COUNT(*)
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.
22.
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 = __________________________________________________;
Correct Answer
mysqli_connect("sit.rp.sg", "admin", "pWd!", "c203project")
mysqli_connect('sit.rp.sg', 'admin', 'pWd!', 'c203project')
mysqli_connect("sit.rp.sg","admin","pWd!","c203project")
mysqli_connect('sit.rp.sg','admin','pWd!','c203project')
mysqli_connect ('sit.rp.sg', 'admin', 'pWd!', 'c203project')
Explanation
Do not add the die() function in the statement.
23.
Complete the pHP statement to execute the SQL query in variable $selectStr. Database connection is stored in variable $conn.$allRows = ______________________________;
Correct Answer
mysqli_query($conn,$selectStr)
mysqli_query ($conn, $selectStr)
mysqli_query($conn, $selectStr)
mysqli_query ($conn,$selectStr)
mysqli_query($conn, $selectStr )
Explanation
Do not add the die() function in the statement.
24.
What is the result of execution of a failed INSERT SQL query?
Correct Answer
D. False
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.
25.
What is the result of execution of a successful SELECT SQL query?
Correct Answer
E. Result object
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.
26.
Choose the most appropriate statement that will check for the successful execution of a SELECT SQL query.
Correct Answer
C. If (mysqli_query($link, "SELECT * FROM keyContacts"))
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.
27.
Which function will get a result row as a numerically indexed array after the successful execution of a SELECT SQL query?
Correct Answer
A. Mysqli_fetch_row($allRows)
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.
28.
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 _______________________________ ;
Correct Answer
FROM keyContacts WHERE email LIKE '%rp.sg'"
FROM keyContacts WHERE email LIKE '%rp.sg' "
from keyContacts where email like '%rp.sg' "
FROM KEYCONTACTS WHERE email LIKE '%rp.sg' "
FROM KEYCONTACTS WHERE email LIKE '%rp.sg'"
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.
29.
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:
Correct Answer
mysqli_fetch_array($allRows)
mysqli_fetch_row($allRows)
mysqli_fetch_array ($allRows)
mysqli_fetch_row ($allRows)
mysqli_fetch_row($allRows )
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.
30.
In a numerically indexed array, what is the index number to access the 2nd item?
Correct Answer
D. 1
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.
31.
Complete the code according to comment provided:
Correct Answer
array
32.
The three blanks in the code have the same answer: The missing code is :
Correct Answer
=>
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.
33.
The following lines are part of a pHP code to retrieve information from database; complete the code according to comment provided:
Correct Answer
$record['contact_name']
$record ['contact_name']
$record["contact_name"]
$record ["contact_name"]
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.
34.
The following lines are part of a pHP code to retrieve information from database; complete the code according to comment provided:
Correct Answer
$rowData [2]
$rowData[2]
$rowData [2 ]
$rowData[2 ]
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.
35.
The following lines are part of a pHP code to register new user into a database; complete the code according to comment provided:
Correct Answer
sha1($passw)
sha1 ($passw)
sha1($passw )
sha1 ($passw )
sha1 ( $passw )
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.
36.
The following lines are part of a pHP code to authenticate user; complete the code according to comment provided:
Correct Answer
mysqli_num_rows($ans
mysqli_num_rows ($ans
mysqli_num_rows($ans)
mysqli_num_rows ($ans)
mysqli_num_rows ( $ans
37.
The following lines are part of a pHP code to authenticate user; complete the code according to comment provided:
Correct Answer
session_start()
session_start ( )
session_start ()
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.
38.
The following lines are part of a pHP code to set session information for an authenticated user; complete the code according to comment provided:
Correct Answer
$_SESSION
39.
The following lines are part of a pHP code to retrieve session information for an authenticated user; complete the code according to comment provided:
Correct Answer
isset
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.
40.
The following 2 lines are part of a HTML document , fill in the blank:
Correct Answer
enctype
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.