CIT 410 Final Exam Multiple Choice part
Assume that the POST method is used. Which of the following statements gets the value of the radio button that's on in the delivery group and stores it in a variable named $card_type? <input type="radio" name="delivery" value="USPS">USPS <input type="radio" name="delivery" value="FedEx">Federal Express <input type="radio" name="delivery" value="UPS">UPS
$card_type = $_POST['delivery'];
A PHP variable begins with what symbol?
! possibly but probably $
To get the value of a cookie, you can use the autoglobal ______________ variable.
$_COOKIE
Once a session is started, which autoglobal can be used to get and set the user's data for a session?
$_SESSION
Which one of the following is the correct PHP command to set a session variable named count with a value of 3:
$_SESSION["count"] = 3;
Given the code that follows: $employees = array(); $employee["name"] = "John Smith"; $employee["age"] = 29; which of these statements assigns "John Smith is 29" to $message?
$message = $employee["name"] . " is " . $employee["age"];
Select the statement which is equivalent to the followiing: $stateCodes = array(); $stateCodes['ME'] = 'Maine'; $stateCodes['MI'] = 'Michigan'; $stateCodes['MO'] = 'Missouri';
$stateCodes = array('ME' => 'Maine', 'MI' => 'Michigan', 'MO' => 'Missouri');
PHP provides a concatenation operator. What symbol is used?
. (dot)
How many times will the while loop that follows be executed? $months = 5; $i = 1; while ($i > $months) { $futureValue = $futureValue * (1 + $monthlyInterestRate); $i = $i+1; }
0
Suppose an array of country codes and country names is created with a statement like this: $country_codes = array('DEU' => 'Germany', 'JPN' => 'Japan', 'ARG' => 'Argentina', 'USA' => 'United States'); If you want to use echo statements to display a table of all of the codes and names, you could code those statements within a loop that starts like this:
foreach ($country_codes as $code => $name) {
The HTTP response for a dynamic web page is passed
from the web server to the browser
The $_SESSION variable for a session
is an associative array
A PHP variable name
is case-sensitive
Which PHP function can be used to determine if a checkbox is checked?
isset
Which attribute of a form element determines how the data is passed to a file?
method
In order to group multiple radio buttons so that only one of the radio buttons can be selected at a time, which attribute of the input element must have the same value for all radio buttons in the group?
name
A cookie that does not expire when the user closes his or her browser is called a(n) ________________ cookie.
persistent
Which type of input validation must be performed?
server-side
To delete a cookie, you
set the cookie's value to an empty string and its expiration date to a time in the past
Consider the two pieces of code below. If the file index.php was called by source.htm in the manner illustrated, what would be displayed? Query String
two
When the web server recieves an HTTP request for a PHP page, the web server calls the
PHP interpreter
Match the SQL keyword with it's associated argument:
Question Correct Match Selected Match SELECT Correct A. database attributes/fields Correct A. database attributes/fields FROM Correct D. database table Correct D. database table WHERE Correct B. Boolean condition Correct B. Boolean condition INSERT INTO Correct C. values/variables Correct C. values/variables
If $totalMonths has a value of 13, what does $message contain after this if statement is executed? $years = $total_months / 12; $years = number_format($years); $months = $total_months % 12; if ( $years == 0 ) { $message = $months . " months"; } else if ( $months == 0 ) { $message = $years . " years"; } else { $message = $years . " years, and " . $months . " months"; }
1 years, and 1 months
After the if statement that follows is executed, what will the value of $discountAmount be? $discount_amount; $order_total = 200; if ($order_total > 200) { $discount_amount = $order_total * .3; } else if ($order_total > 100) { $discount_amount = $order_total * .2; } else { $discount_amount = $order_total * .1; }
40
What will be the output of the following PHP code? <?php function calculate($param) { $abc = 10; return $param + $abc; } echo calculate(30); ?>
40
In the code below, the key 'GenreName' comes from what? if ($result = mysqli_query($connection, $sql)) { while($row = mysqli_fetch_assoc($result)) { echo $row['GenreName'] . '<br>'; } }
A field/attribute from the database table being queried.
When we say that PHP variables are "dynamically typed" we mean that
A variable type can be an integer, then later a string, and then later an object (for instance)
Best practice suggests putting database connection code outside of the public_html directory. Which of the following is NOT a reason for doing so?
The database may not be located at the same host.
Which of the following is NOT related to security?
Assigning $_GET or $_POST array variables to scalar variables
Considering the same code: require_once('../config.php'); $connection = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME); The four parameters in the mysqli_connect function are capitalized because:
They are defined as constants
Which one of the following is the correct PHP to output a message to a web page:
echo 'hello';
Consider the PHP code below: require_once('../config.php'); $connection = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME); What is the best way to describe the config.php file?
It contains a hard-coded user name and password combination to gain access to the given database on the given server.
Which of the following is not a type of input validation?
Checking for leading or trailing spaces
________________ provide a way for a web application to store information in the user's web browser and retrieve it every time the user requests a page
Cookies
When preforming a simple MySQL query such as INSERT, what is the correct order for the following tasks?
Correct1. Connect to the database. Correct2. Write the query string. Correct3. Execute the query. Correct4. Close the database connection.
Which method of the form appends values to the URL to pass data?
GET
Sessions solve which of the following problems?
HTTP is a stateless protocol
What will be the output of the following PHP code? <?php $abc = 100; echo "Value of abc = $abc"; ?>
Value of abc = 100
Use the ________ attribute on the <form> tag to specify the name and location of the script that will process the form control values.
action
The array $stateCodes in the previous 2 questions is what kind of array?
associative
What is the name of the variable resulting from this code if the last value (Grad school) is selected? select list
degree