Study your flashcards anywhere!

Download the official Cram app for free >

  • Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off

How to study your flashcards.

Right/Left arrow keys: Navigate between flashcards.right arrow keyleft arrow key

Up/Down arrow keys: Flip the card between the front and back.down keyup key

H key: Show hint (3rd side).h key

A key: Read text to speech.a key


Play button


Play button




Click to flip

46 Cards in this Set

  • Front
  • Back

There can be only one HTML form per html page. T/F


Suppose an HTMLform generates the query string:

when the forms issubmitted and after the various input fields have been filled. Assuming the originating HTML form lies inthe same directory as the target script single.php, what is the form's HTMLsyntax? Fill in the blanks below:

<form _________________________________________________________________ >

<inputtype = text _________________________________________________________ >

<inputtype = password _____________________________________________________>

<input type = _____________________________________________________________>


<form action = "single.php"method="get" >

<input type=text name="username" >

<input type=text name="password" >

<input type=submit >


What agent receives the data from a form?

A web server like the apache server on

name a commonly used website that allows a programmer to test a mail function in a PHP script

from your own experience this term, if a properly formed PHP mail function fails to deliver an email message to a test email site the most likely cause is:

the problem lies within the email server the PHP mail function sends the email request to

In Assignment 02, the grades fora particular assignment like A1 were to be updated only if the checkboxassociated with the grade input slider was checked off. Assume the checkbox for the grade A1 on the update form is named "A1CN" and has an id "A1CI" and that the action for the grades form is "grades.php". Write the PHP code for grades.php thatdetermines whether the grade A1 should be updated. Ignore other inputs like A2 or Participation.Don't write the code that does the actual update. Just write the code that uses the form input forA1 and its checkbox to determine if the update should be done. This only requires a line or two of codedepending on how you do it.

Assume the grades.html form only hasinputs for: a password field, the A1 grade, and the A1 checkbox, and thatgrades.php handles the request on the web server. The first two are text fieldsand the last is a checkbox. Assume these three inputs have names: password, A1 and A1C. Assume these inputs also have id'spasswordId, A1Id, and A1CId, respectively. Write the browser generated URLif the form is submitted using the defaultHTTP method with a password value of 007, where A1 has a value of 40, and the checkboxis unchecked.

Assume the first part of the urlgenerated is that the HTML form and the grades.phpscript lie in the directory 202/asgt1directly under the public_htmldirectory. Complete the rest of theurl.

A PHP program that uses data from an HTML form and the $_GET associate array must know the names of any of the HTML Form input fields it needs to access. T/F


an online MySQL database cannot be concurrently accessed by multiple PHP scripts originating from different users who are connected tot he database. T/F


What happens after a database has been properly connected to and a PHP script executes the following statements:

$s = "select * from GRADEEES";

print "$s<br><ech>";

The PHP string $s is echoed to the browser by the print but the select statement is not executed.

Assume an SQL statement has been executed by a script. Define a PHP or-die statement so that when an SQL error occurs the statement will:

ouput an error message that starts on a new line in the browser with the message content enclosed in an HTML heading element that makes the displayed text large

(mysql)error()="") or die ("<br><h2>Error is: " . mysql_error() . "</h2><br>");

Let SECRET [pass(varchar(60))] be a single column database table with a single attribute named pass which is of type varchar and length a maximum of 60 characters. the tables is assumed to store a "hashed" copy of a password. That is, a copy of a password that has been scrambled by the sha1 function so it's unrecognizable and undecipherable. Write PHP code that inserts a hashed copy of a plaintext password into SECRET. Assume the plaintext copy comes from an HTML form where the password field is named "pass".

$pwd = $_REQUEST["pass"];

$s = "insert into SECRET values sha1('$pwd')";


assume the database table SECRET[pass] defined aboe. write PHP code to test if a hashed plaintext password retrieved from an HTML Form, where it is named "pass", is contained in SECRET

$pwd = $_REQUEST["pass"];

$s = "select * from SECRET where sha1('$pwd') = pass";

$t = mysql_query($s);

if(mysql_num_rows($t)==0){ die ("password is not in database");};

Write the code for an HTML5 input text field named "text" with placeholder content of "Enter letters and digits only", a tooltip hint that says: use letters and digits only; with the input history off and which prevents the form that contains it from being submitted until the field is filled in.

<input type="text" name="password" placeholder="Enter password",

required="required" autocomplete="off",

title=" use letters and numbers " />

Write the code for an HTML5 slider input with a name of "priority" step size 1, min value of 0, maximum value of 9, and initial default value of 5. Give the element an ID value as well.

<input type="range" name ="priority" id="priority" min=0 max=9 step=1 value=5 />

make an html5 output element and an associated oninput event in the form tag that copies the slider value to the output element so it can be seen


Write the code for a PHP function named authenticate with 2 arguments corresponding to the name and password of a user being authenticated. Assume the password lies in the database and is already encrypted with the sha1 hash function. the authenticate function should check if the name and the sha1 encrypted password match some row of the database table named credentials. The function returns true if there is a match and false if not. Assume the script involved is already connected to the database.

function authenticate ($name, $pass)


var $status = false

$s = "select * from credentials where name =

'$name' and pass = sha1('$pass')";

if (mysql_num_rows($t)>0) $status = true;

return $status;


Assume a definition for the function authenticate (as considered in previous question) is contained in a PHP file named myfunctions.php Invoke authenticate in a PHP script named test.php lying in the same directory as myfunctions.php. Assume test.php has already connected to the database. Assume that the test.php has already accessed the input values required for the authenticate function and stored them in $n and $p, respectively. The password parameter $p is in plaintext (that is not yet encrypted). Invoke authenticate in test.php in such a way that test.php terminates if authenticate returns false but otherwise continues execution. Two statements are required to do this.


(authenticate($n, $p) ) or die("invalid credentials");

Thetable REGISTER used in Assignment02 has multiple columns. These included the username column which was a primary key and the email address column which was notprimary but was unique. Write the codefor a PHP function named duplicate withtwo arguments corresponding to the name& email of a user being added to REGISTER. The duplicatefunction should test whether the nameor email address appear in duplicate since in that case the usershould not be added to the table. Thefunction returns true if the user can be added and false otherwise. Assume the script involved is alreadyconnected to the database.

similar but not identical to the definition of the authenticate function described above.

Assumea pair of password elements in an HTML form have id's "one" and"two" respectively, and that a span element on the page has an id"warn". Define a Javascriptfunction compare ( ) that comparesthe values of the passwords and does the following:

1.If password values don't match, comparestores a warning message ("mismatch") in the span element, sets thecontents of the "two" input field to an empty string, and returns false.

2.Otherwise, compare clears thecontents of the span element (erasing any earlier warning) and returns true.

Assumethe function is called when an onblurevent occurs on the password field "two". However, only write thecode for the Javascript function. If you write the associated HTML code and itis wrong you will lose points even though it was extra. This password comparison problem was part ofAssignment 02.

Writethe HTML code needed to:

a. Definethe onblur event referred to in thesolution to the above problem

b. Ensurean empty password field cannot besubmitted to the server

c. Definethe initially empty span element where the warning from the Javascript goes.

Writethe PHP code needed to access the participationfield from the grades.html page used in Assignment02. The code should assume:the data is transmitted using a get method, the HTML element's name is "participation" and its id is "participationId", and that the data is transformed using the usualPHP screening data transforming function to prevent SQL injection.

examplesposted during the term in connection with Assignment 02.

Writethe PHP code needed to update the Participationcolumn in the database GRADES. Assumethe username and course are in $usernameand $course, and the Participation contribution is in $Participation. Write the PHP statements to define therequired SQL string and execute it.

seeexamples posted during the term in connection with Assignment 02

Writethe PHP code needed to update the Totalcolumn in the database GRADES. Assumethe username and course are in $usernameand $course. Write the rest of the PHPstatements needed to define the required SQL string and execute it.

seeexamples posted during the term in connection with Assignment 02.

What HTTP default methodis assumed for an HTML Form:

(a) GET method

(b) Select method


(d) It depends on the target script and thebrowser

A) GET method

Implementa CSS3 transition so that when a divelement in an html page is hovered over by the cursor/mouse, the div's widthchanges from an initial statically defined value of 200px to 400px. Make the div's background cyan colored so youcan see the special effects. Define thestyle rules so the transition works in Chrome by using the appropriate browser-specific prefix (webkit-). The triggering event for the transition is a hover on a div. Notice that no Javascript or Flash isrequired for the animated effect.

see the css.html example posted.

Thesame kind of effect can be applied to other CSS properties. You can createpowerful as well as subtle visual effects using these CSS3 capabilities.

Thisis intended to illustrate the effects possible using the CSS3 animation property to gradually changethe width of a div element, as well as the font size of its text, and the angle of rotation of the div. Over theperiod of the animation, the:

a. widthvaries from 200 to 300 px, and back

b. font-sizevaries from 10pt to 30pt, and back

c. Angleof rotation varies from 0 degrees to 10 degrees to -10 degrees, and back to 0degrees.

Theanimation occurs over a 4 second interval and repeats. The time intervals are 0%, 25%, 65% and 100%.

see waverShapePureCSS_Anim.html example posted.

Definea PHP function named getSafeData($p) whose input argument isthe name of an HTML input field andwhich returns the value of that input afterit has been transformed using mysql_real_escape_string.

referto Video 6C (see 5 minutes into the video,and up to the end)

Writean html5 text input element that accepts only input that begins with two tofour capital letter followed by one to three even digits. The input should allow leading and trailingspaces but no commas or other spaces.

<input type=text patter = "^[]*[A-Z]{2,4][01468]{1,3}[]*$" required>

Define a regex pattern for a full namewith an optional middle initial. Thelast name can have a single quote as in Joseph A. O'Malley in which case the letter after thequote must also be capitalized.

Possible solution: ^[A-Z][a-z]+\s+([A-Z]\.\s+)?[A-Z](['][A-Z])?[a-z]+$

Aninput text element has an id="name" and must follow a regex rule so thatit accepts only a single digit followed by three capital letters. The rule is enforced by a Javascript functionnamed check ( ) that is invoked when the form is submitted (the opening formtag is <form action="hello.txt onsubmit="check( )" >. If check() returns false the submission isblocked. Complete the following code forcheck ( ) so it enforces the rule on the text element.

functioncheck ( ) {

var result = true


fillin the code here that defines the pattern, gets the input data to test, andsets result to false if the rule fails


return result


functioncheck ( ) {

var result = true

var p = /^[0-9][A-Z]{3}$/

vars = document.getElementbyId("name").value

if ( (p) == -1)

{ alert ("bad input")

result= false


return result


Ifan HTML page omits its DOCTYPE tagthen the browser will fall back to interpreting the page in (a)____________________________________.

TheDOCTYPE declaration for HTML5 is

(b)___________________________________ .

A) Quirks mode
B) <!DOCTYPE html5>

What HTML special character code represents thesymbol for the angular bracket (<)?

What HTML notationis used to force a space character in an HTML page (the answer is not a simplespace.)

A) The ampersand (&) is designated by & (including the semicolon)

B) The characters for a space is   (including semi colon)

Supposea script x.php is triggered using an AJAX function call in x.html. Where does the output from all of the PHPprint statements in x.php end up in the x.html AJAX environment? That is whatJavascript variable will contain the output when x.php terminates. Assume the HTTP object used by the AJAX isnamed http.
seeposted AJAX videos

Assume the same circumstances as in the previousquestion. If the PHP script x.php is:



echo "<br><i>Hello</i>";


Then whatis sent to the invoking AJAX system?
seeposted AJAX videos. You canexperimentally discover the answer by making a simple example that does thisand using the developer tool to look at the HTTP response that the PHP sends.

Inthe AJAX examples that we have considered the get request by the AJAX includes the sub-string:

"&junk="+Math.random()as part of the request query string.

a. Isan error caused if the targeted PHP script ignoresthe transmitted variable junk used inthe query. Yes No

b. Ifthe string "&junk="+Math.random() is replaced by "&junk="+100*Math.random( ) does the newstring accomplish the same objective as the original string? Yes No

Ifthe PHP script targeted by an AJAX request does not exist on the server doesthat cause a:

a. Javascripterror

b. HTMLerror

c. PHPerror

d. Noneof the above

A) WhatphpMyAdmin feature allows you to create an SQL script?

B) WhatphpMyAdmin feature allows you to execute an SQL script?

C) SQLscripts can define & populate a DB table but primary keys must be definedin phpMyAdmin?
D) WhatSQL function sets the date and time of a datetime column?

E) WhatSQL function sets the date of a datetime column?

A) export

B) import

C) false

D) Now()

E) Date()

a. WhatLinux command and options sets up anSSL connection between a secure terminal and a secure site like web.nji.eduaccessed that to allow HTTP requests to be sent for a file under thepublic_html directory on the site like /~mchugh/202/table.html. Include the correct port number for a securehttps connection.

openssls_client -connect
Whatdefault port does a http web server accessed by a secure connection listen on?
Ans: port 443
Whatdefault port does a http web server accessed by a secure connection listen on?
WhatHTTP request will access the file /~mchugh/202/table.html under the public_html directory on
GET/~mchugh/202/table.html HTTP/1.0
Ifyou make an HTTP request for GET /~mchugh/202/us.gifff HTTP/1.0 where the name of the requestedfile is misspelt what will the HTTP response header looklike

Youwill get a file not found response inthe header like:

GET/~mchugh/202/us.gifff HTTP/1.0

HTTP/1.1 404 Not Found

Date:Sat, 25 Apr 2015 18:52:36 GMT

Hint: This is like the code to wrap DB data in anHTML table – except it is done for an HTML menu instead.

Letcountries [country, code] be a database table. Suppose the SQL statement Select country, code from countries has just been executed in a PHP script andthe results saved in $t. Suppose the retrieved data has attributes country and code.

Writethe PHP code needed to "wrap" these results in an HTML menu or selectelement. The menu element should benamed "list". Make theretrieved country values the visiblecontents of the option elements in the select/menu element and make thecorresponding option value for the row be the code retrieved for that country. Remember actual HTML menus look like:

<select name="list">

<option value="USA"> United States of America </option>

<option value="CAN"> Canada </option>


Butthe menu your PHP code should generate is not the above menu but one based onthe data the SQL query retrieves from the database. Construct the menu using PHP by combiningHTML menu tags with the data retrieved. This defines both the visible contents of the menu (in the above examplethe visible text would be: United Statesof America and Canada) with thevalues of the code providing the hidden values for the menu's rows (in aboveexample this would be USA and CAN).

print"<select name = "list" >"; //Start select element

while ( $r = mysql_fetch_array ( $t ) ) //Loopover rows $r of results $t


$name = $r [ "country"];

$SSN = $r [ "code"];

print "<option value =\"$code\" >"; //Define value for menuchoice

print $country ; //Definevisible menu choice

print "</option>" ; //Endoption tag


print"</select>"; //Endselect tag

Give a pattern for a zipcode that allowsboth an ordinary 5-digit zipcode and an optional extra 4-digit extension to the basic zipcodelike: 77777-8888

the optional part of the zip coderequires using the ? operator. Test yoursolution in

Supposean AJAX named send( ) function makesuse of an HTTP object named contactto transmit a request to a PHP script named A1.phplying in the same directory as the HTML page making the request. The data sent comes from a Javascriptvariable named w. The receiving PHP script expects its inputfrom the requestor to be named u. Write the code needed to make the request. Ignore any code needed to avoidcaching side-effects in the AJAX request. ( 'get' , 'A1.php?u=' + w )