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. All of the above
  1. The logical operator && checks for what?
  1.  
  2. If both arguments are true.

  1. Immediately after sending a form with the attribute method=”post”, the data can be accessed via:
  1.  
  2. $_POST or $_REQUEST superglobal arrays
  3.  

True / False (10 x 2.5 points each):

  1. The isset() function can be used to check if a variable has been defined.

True

  1. You don’t need to sanitize your form data, the server will automatically escape any dangerous user input.

False

  1. A JOIN is when you write a SELECT statement that involves multiple tables

True


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’];

    if( $score >= 5000 ){
            echo $message;
    }




  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’];

        
if($logged_in){

header(‘Location:secret-page.php’);

}







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.

    SELECT body, date
    FROM comments
    WHERE user_id = 1
    ORDER BY date ASC











  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

INSERT INTO comments

(user_id, date, body, post_id)

VALUES

(12, now(), ‘Happy St. Pats Day!’, 6)