WIP400 - Programming for Designers:

Mid-Term & Final PRACTICE QUESTIONS

Multiple Choice (10 x 2.5 points each):

Circle the option that best answers each question.

  1. How do you write a comment in PHP?
  1. //
  2. #
  3. /* */
  4. All of the above
  1. The logical operator && checks for what?
  1. If either or both arguments are true.
  2. If both arguments are true.
  3. If one, but not both arguments are true.
  4. If none of the arguments are true.
  1. Immediately after sending a form with the attribute method=”post”, the data can be accessed via:
  1. $_SESSION superglobal array
  2. $_GET or $_POST superglobal arrays
  3. $_POST or $_REQUEST superglobal arrays
  4. $_SESSION, $_GET and $_POST superglobal arrays

True / False (10 x 2.5 points each):

  1. The isset() function can be used to check if a variable has been defined.
  1. True
  2. False
  1. You don’t need to sanitize your form data, the server will automatically escape any dangerous user input.
  1. True
  2. False
  1. A JOIN is when you write a SELECT statement that involves multiple tables
  1. True
  2. False


Hand Coded Problems (5 x 10 points each). Use the provided code as a starting point. You do not need to escape into PHP:

  1. Using an IF statement, finish the code below to display the message if the user’s score is at least 5,000.

    <?php 
    $message = ‘You won the game!’;
    $score = $_REQUEST[‘score’];



  2. Finish the code below to redirect the user to the file ‘secret-page.php’ if they are logged in. The session variable ‘loggedin’ will be true if they are logged in.

<?php

session_start();

$logged_in = $_SESSION[‘loggedin’];






Note: the following questions will use this table as a reference.

You only need to write the SQL statements, no PHP is necessary.

Table name: comments

comment_id

user_id

date

body

post_id

1

2

2016-03-09

I love this post!  great job, you.

1

2

1

2016-03-09

Hmm, I don't think I agree

2

3

1

2016-03-15

It's taco tuesday today!

3


  1. Write an SQL statement to retrieve the date and body fields of all comments written by user 1, oldest comment first.












  2. Write an SQL statement to add the following comment to the comments table:

User: 12

Date: (get the current date)

Body: Happy St. Pats Day!

Post: 6