Web Programming Theory Test
How do you store a cookie in the browser using PHP?
A cookie is often used to identify a user. Cookies are bits of data that a web browser stores on your visitor's computer. They can be very useful if you need to store things like your visitor's preferences or login data (if your site has a membership facility) or other things that are specific to a particular visitor. With PHP, you can both create and retrieve cookie values. A cookie is created with the setcookie() function. setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace. Only the name parameter is required. All other parameters are optional. <?php $cookie_name = "user"; $cookie_value = "John Doe"; setcookie ($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day ?> <html> $_COOKIE superglobal variable is used to retrieve a cookie value.
jQuery Validation Plugin: method
A validation method implements the logic to validate an element, like an email method that checks for the right format of a text input's value. A set of standard methods is available, and it is easy to write your own.
jQuery Validation Plugin: rule
A validation rule associates an element with a validation method, like "validate input with name "primary-mail" with methods "required" and "email".
Briefly explain, with example, an AJAX call using JQuery.
AJAX(Asynchronous JavaScript And XML) is a developer's dream, because you can: Update a web page without reloading the page. Request and receive data from a server - after the page has loaded. Send data to a server - in the background. AJAX is not a programming language. AJAX just uses a combination of: A browser built-in XMLHttpRequest object (to request data from a web server) JavaScript and HTML DOM (to display or use the data) AJAX allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page. The ajax() method is used to perform an AJAX (asynchronous HTTP) request. All jQuery AJAX methods use the ajax() method. This method is mostly used for requests where the other methods cannot be used. $.ajax({name:value, name:value, ... }) The parameters specifies one or more name/value pairs for the AJAX request.
jquery closest()
Begins with the current element. Travels up the DOM tree and returns the first ancestor that matches the passed expression. The returned jQuery object contains zero or one element
Briefly explain the difference between "col-lg-XX" and "col-xs-XX" class attributes used in Bootstrap.
Bootstraps column classes are what makes up the individual columns of the grid. It's main purpose is to align your components into colurmns. They're designed to have 3 sections: column-for which view port- size of the column Large devices vs Extra small devices
GET vs. POST
Both GET and POST create an array that holds key/value pairs, where keys are the names of the form controls and values are the input data from the user. Both GET and POST are treated as $_GET and $_POST. These are superglobals, which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special. $_GET is an array of variables passed to the current script via the URL parameters. $_POST is an array of variables passed to the current script via the HTTP POST method.
15. Which property is used to change the font of an element? font-family Both font-family and font can be used font
Both font-family and font can be used
What does CSS stand for?
Cascading Style Sheets
difference between session and cookie
Cookies are client-side, sessions are server-side. ... Any sensitive data should be stored in session, as cookies are not 100% secure. An advantage of cookies is that you can save memory on your server that would normally be storing session data
What is DOM in JQuery?
DOM = Document Object Model. allows programs and scripts to dynamically access and update the content, structure, and style of a document. jQuery comes with a bunch of DOM related methods that make it easy to access and manipulate elements and attributes. Three simple, but useful, jQuery methods for DOM manipulation are: 1. text() - Sets or returns the text content of selected elements. 2. html() - Sets or returns the content of selected elements (including HTML markup). 3. val() - Sets or returns the value of form fields. Before you execute any DOM manipulation JavasScript or jQuery code you need to tell the browser to execute your code only when the DOM is ready i.e when all page elements are loaded. Otherwise your code may not function properly. You simply need to listen for the ready event which is emitted by the browser when DOM is ready.
What does HTML stand for?
Hyper Text Markup Language
21. What is the most common type of join?
INNER
host
Optional. Specifies a host name or an IP address
What does PHP stand for?
PHP originally stood for Personal Home Page, but it now stands for PHP: Hypertext Preprocessor.
The PHP syntax is most similar to:
Perl and C
LEFT (OUTER) JOIN:
Return all records from the left table, and the matched records from the right table
RIGHT (OUTER) JOIN:
Return all records from the right table, and the matched records from the left table
FULL (OUTER) JOIN:
Return all records when there is a match in either left or right table
(INNER) JOIN:
Returns records that have matching values in both tables
9. With SQL, how do you select all the records from a table named "Persons" where the value of the column "FirstName" starts with an "a"? SELECT * FROM Persons WHERE FirstName='%a%' SELECT * FROM Persons WHERE FirstName LIKE 'a%' SELECT * FROM Persons WHERE FirstName LIKE '%a' SELECT * FROM Persons WHERE FirstName='a'
SELECT * FROM Persons WHERE FirstName LIKE 'a%'
13. Which SQL statement is used to return only different values?
SELECT DISTINCT
24. How do you group selectors? Separate each selector with a comma Separate each selector with a space Separate each selector with a plus sign
Separate each selector with a comma
required pattern=".(8.15)"
Sets the min and max lengths for an input type
In PHP you can use both single quotes ( ' ' ) and double quotes ( " " ) for strings:
T
PHP allows you to send emails directly from a script
T
PHP can be run on Microsoft Windows IIS(Internet Information Server):
T
The die() and exit() functions do the exact same thing.
T
The if statement is used to execute some code only if a specified condition is true
T
parent( [selector] ) is used to get the parent of an element in JQuery? (T/F)
T. The parent() method returns the direct parent element of the selected element.
HTML5 textbox
Text boxes in HTML5 forms are the most basic elements that forms use in the collection of data. Text boxes in HTML5 forms are typically used when the input requires a single line of text. You must also specify a unique name for the text box using the NAME attribute.
What is !important used for?
The !important rule overrides that particular property. It means, essentially, what it says; that 'this is important, ignore subsequent rules, and any usual specificity issues, apply this rule!'. An !important rule works like this: p { color: red !important; } #thing { color: green; }
What is the use of $_GET[variable_name]
The $_GET variable is used to get data from a form that is written in HTML. Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar). The GET method is restricted to send up to 2048 characters only. Before you can use the the $_GET variable you have to have a form in html that has the method equal to GET. Then in the php, you can use the $_GET variable to get the data that you wanted. The $_GET syntax is ($_GET['name of the form field goes here']). <?php // It will display the data that it was received from the form called name echo ($_GET['name']); ?> //This is the html form that creates the input box and submit button //The method for the form is in the line below <form action="name of the php file that has the ($_GET[]) variable in it" method="GET"> <input type="text" name="name"> <input type="submit" value="Submit"> </form>
cookie Parameters: domain
The (sub) domain that the cookie is available to. Setting this to a subdomain (such as 'www.example.com') will make the cookie available to that subdomain and all other sub-domains of it (i.e. w2.www.example.com). To make the cookie available to the whole domain (including all subdomains of it), simply set the value to the domain name ('example.com', in this case).
.parents()
The .parents() and .parent() methods are similar, except that the latter only travels a single level up the DOM tree. Also, $( "html" ).parent() method returns a set containing document whereas $( "html" ).parents() returns an empty set.
jquery :parent
The :parent selector selects all elements that are the parent of another element, including text nodes.
how do you prevent the default action for an event like form submission, in JQuery?
The event.preventDefault() method stops the default action of an element from happening. For example: Prevent a submit button from submitting a form. Prevent a link from following the URL. $(document).ready(function(){ $("form").submit(function(event){ event.preventDefault(); alert("Submit prevented"); }); });
<?php $cookie_name = "user"; $cookie_value = "John Doe"; setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day ?> <html> <body> <?php if(!isset($_COOKIE[$cookie_name])) { echo "Cookie named '" . $cookie_name . "' is not set!"; } else { echo "Cookie '" . $cookie_name . "' is set!<br>"; echo "Value is: " . $_COOKIE[$cookie_name]; } ?>
The following example creates a cookie named "user" with the value "John Doe". The cookie will expire after 30 days (86400 * 30). The "/" means that the cookie is available in entire website (otherwise, select the directory you prefer). We then retrieve the value of the cookie "user" (using the global variable $_COOKIE). We also use the isset() function to find out if the cookie is set
13. How do you display hyperlinks without an underline? a {decoration:no-underline;} a {text-decoration:none;} a {text-decoration:no-underline;} a {underline:none;}
a {text-decoration:none;}
17. How do you display a border like this: The top border = 10 pixels The bottom border = 5 pixels The left border = 20 pixels The right border = 1pixel? border-width:10px 5px 20px 1px; border-width:10px 20px 5px 1px; border-width:5px 20px 10px 1px; border-width:10px 1px 5px 20px;
border-width:10px 1px 5px 20px;
What is the difference between include_once() and require_once()?
both statement can be used to include a php file in another one, when you may need to include the called file more than once. If it is found that the file has already been included, calling script is going to ignore further inclusions. Include will let the script keep running (with a warning) if the file is missing. Require will crash if it's missing.
.find()
can traverse recursively into children, children of those children, and so on.
23. How do you select all p elements inside a div element? div + p div p div.p
div p
Briefly explain the use of Session variable and it's use in maintaining the session state
exist only while the user's session with your application is active. Session variables are specific to each visitor to your site. they are used to store user-specific information that needs to be accessed by multiple pages in a web application. A session is started with the session_start() function, and must be the very first thing in your document. To maintain session state, Session variables store user information to be used across multiple pages (e.g. username, favorite color, etc). By default, session variables last until the user closes the browser.
16. How do you make the text bold? style:bold; font:bold; font-weight:bold;
font-weight:bold;
What is the correct way to open the file "time.txt" as readable? open("time.txt"); open("time.txt","read"); fopen("time.txt","r"); fopen("time.txt","r+");
fopen("time.txt","r");
Bootstrap is the world's most popular ...
front-end component library.
What is the use of $_POST[variable_name]?
in PHP, the $_POST variable is used to collect values from HTML forms using method post. Information sent from a form with the POST method is invisible and has no limits on the amount of information to send. • The POST method does not have any restriction on data size to be sent. • The POST method can be used to send ASCII as well as binary data. • The data sent by POST method goes through HTTP header, so security depends on HTTP protocol. By using Secure HTTP, you can make sure that your information is secure. • PHP $_POST associative array is used to access all the sent information by POST method. • Variables are not visible in the URL so users can't bookmark your page.
validation behavior for username and firstname
jQuery Validation Plugin. We add the required rule to all fields of the form. The username field has an added rule that ensures its minimum length is 2 characters. After specifying the rules, we set the error messages that will be shown whenever a rule fails. (like we did in class).
20. How do you make a list that lists its items with squares? list-type: square; list-style-type: square; list: square;
list-style-type: square;
18. Which property is used to change the left margin of an element? indent padding-left margin-left
margin-left
.children()
only operates on direct children
25. What is the default value of the position property? static absolute fixed relative
static
Which HTML attribute is used to define inline styles?
style
14. How do you make each word in a text start with a capital letter? You can't do that with CSS text-transform:uppercase text-transform:capitalize
text-transform:capitalize
Action property
what file will load when user clicks
How to ensure the DOM is "Ready" for manipulation, in JQuery?
when all page elements are loaded
.nav > .nav-item { ... }
will just go one level down so the grandchildren are not ruled by that rule.
The onSubmit property in the FORM tag
will link to the JS file when the form is submitted. The SUBIT TYPE will run the onSubmit JS. If it returns TRUE it then the ACTION properties of the FORM tag. If it returns FALSE the form action is not performed.
.nav .nav-item { ... }
will target children and grandchildren and so on
sessionstorage store and retrieve
HTML web storage; better than cookies. The sessionStorage object is equal to the localStorage object, except that it stores the data for only one session. The data is deleted when the user closes the specific browser tab. // Store sessionStorage.setItem("lastname", "Smith"); // Retrieve document.getElementById("result").innerHTML = sessionStorage.getItem("lastname");
Bootstrap is open source toolkit for developing ...
HTML, CSS and JS
<?php; $db_handle = mysqli_connect($db_server_name, $db_user_name, $db_password); ?>
"$db_handle" is the database connection resource variable (A resource is a special variable, holding a reference to an external resource). "mysqli_connect(...)" is the function for php database connection "$server_name" is the name or IP address of the server hosting MySQL server. "$user_name" is a valid user name in MySQL server. "$password" is a valid password associated with a user name in MySQL server.
21. How do you select an element with id "demo"? #demo demo *demo .demo
#demo
All variables in PHP start with which symbol?
$
Which superglobal variable holds information about headers, paths, and script locations? $_SERVER $_GLOBALS $_GET $_SESSION
$_SERVER
How do you create an array in PHP? $cars = "Volvo", "BMW", "Toyota"; $cars = array("Volvo", "BMW", "Toyota"); $cars = array["Volvo", "BMW", "Toyota"];
$cars = array("Volvo", "BMW", "Toyota");
What is the correct way to add 1 to the $count variable? $count =+1 $count++; ++count count++;
$count++;
Difference between .nav .nav-item { ... } and .nav > .nav-item { ... }
.navbar-nav {} will target children and grandchildren and so on while .navbar-nav > will just go one level down so the grandchildren are not ruled by that rule.
22. How do you select elements with class name "test"? test *test #test .test
.test
7. How do you insert a comment in a CSS file? // this is a comment // / this is a comment / // this is a comment ' this is a comment
/ this is a comment /
What is a correct way to add a comment in PHP? \...\ <!--...--> /.../ <comment>...</comment>
/.../
Bootstrap is used to fulfill following objectives (Select all applicable) 1. Build Responsive Design. 2. Mobile-first design. 3. edit CSS. 4.Server side coding.
1. Build Responsive Design. 2. Mobile-first design.
<!--?php $database = mysqli_connect ("HOST", "USER_NAME", "PASSWORD"); mysqli_select_db($database,"DATABASE_NAME"); ?-->
1. Create a database connection. mysqli_connect() function opens a new connection to the MySQL server. mysqli_connect(host, username, password, dbname, port, socket); 2. The mysqli_select_db() function is used to change the default database for the connection. mysqli_select_db(connection,dbname);
How do you create a textbox using HTML5
1. Create an input element. The <input> tag creates the general structure of the element. 2. Set the type to "text" to indicate that you're building a standard text element, not something more elaborate. 3. Add an id attribute to name the element. This becomes very important when you add JavaScript to the page because your JavaScript code will use the ID to extract data from the form. 4. Add default data. You can add default data if you want, using the value attribute. Any text you place in the value will become the default value of the form. 1. <label>Text box</label> 2. <input type = "text" 3. id = "myText" 4. value = "text here" />
The 3 ways to insert CSS into your web pages:
1. With an external file that you link to in your web page: <link href="myCSSfile.css" rel="stylesheet" type="text/css"> 2. By creating a CSS block in the web page itself; typically inserted at the top of the web page in between the <head> and </head> tags: <head> <style type="text/css"> p { padding-bottom: 12px; } </style> </head> 3. By inserting the CSS code right on the tag itself: <p style="padding-bottom:12px;">Your Text</p>
How to select elements with class atrribute "myClass" with JQuery (Select one): 1. $("#myClass") 2. $(".myClass") 3. $("myClass") 4. $myClass
2
7. Select all the ways in which CSS is applied to a webpage (Select all applicable)- 1. Write CSS code in <css> tags. 2. Include the external CSS file. 3. Use "style" attribute. 4. Use <style> block to specify CSS instructions.
2. Include the external CSS file. 3. Use "style" attribute
The type="hidden" fields in HTML forms are required for (Select the right answer)? 1. Password Protection 2. Encryption 3. They are of no use 4. To store values from server side code
4. To store values from server side code
2. What is the correct HTML for referring to an external style sheet? <link rel="stylesheet" type="text/css" href="mystyle.css"> <style src="mystyle.css"> <stylesheet>mystyle.css</stylesheet>
<link rel="stylesheet" type="text/css" href="mystyle.css">
Which HTML tag is used to define an internal style sheet?
<style>
Which operator is used to check if two values are equal and of same data type?
===
Different Types of SQL JOINs
A JOIN clause is used to combine rows from two or more tables, based on a related column between them. (INNER) JOIN: LEFT (OUTER) JOIN: RIGHT (OUTER) JOIN: FULL (OUTER) JOIN: SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;
whats a cookie
A cookie is information stored on your computer by a website you visit. In some browsers, each cookieis a small file, but in Firefox, all cookies are stored in a single file, located in the Firefox profile folder. Cookies often store your settings for a website, such as your preferred language or location.
col-xs-XX
Extra small devices Phones (<768px) - .col-xs-
Cookies are stored on the server (T/F).
F
col-lg-XX
Large devices Desktops col-lg-* - 992px
What is the difference between mysqli_connect and mysql_connect?
MySQLi provides a object-oriented way for accessing MySQL databases. mysqli_*() is the modern way to access a MySQL database via PHP. • Mysqli supports supports charsets, mysql does not • Mysqli supports prepared statements, mysql does not • Mysql does not support multiple statements, mysqli does
19. When using the padding property; are you allowed to use negative values?
No
14. Which SQL keyword is used to sort the result-set?
ORDER BY
What is the localStorage object in html5 used for?
The localStorage and sessionStorage properties allow to save key/value pairs in a web browser. The localStorage object stores data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.
What is the sessionstorage object in html5 used for?
The localStorage and sessionStorage properties allow to save key/value pairs in a web browser. The sessionStorage object stores data for only one session (the data is deleted when the browser tab is closed).
cookie Parameters: path
The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in.
cookie Parameters: expires
The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch(unix time).
cookie Parameters: value
The value of the cookie. This value is stored on the clients computer; do not store sensitive information. Assuming the name is 'cookiename', this value is retrieved through $_COOKIE['cookiename']
Explain the purpose of while($row = mysqli_fetch_array($query))
This does the following: 1. mysql_fetch_array retrieves and returns the next row 2. the row is assigned to $row 3. the expression is evaluated and if it evaluates to true, the contents of the loop are executed 4. the procedure begins anew Fetch a result row as an associative array, a numeric array, or both. mysqli_fetch_array() is an extended version of the mysqli_fetch_row() function.
How to get the innerHTML of an element using JQuery?
To get the innerHTML of a div tag in jQuery, use the class with innerHTML.