Psychology Experiments on the Web Using PHP and MySQL

Similar documents
HTML Summary. All of the following are containers. Structure. Italics Bold. Line Break. Horizontal Rule. Non-break (hard) space.

Unit 10 - Client Side Customisation of Web Pages. Week 5 Lesson 1 CSS - Selectors

CSS Cascading Style Sheets

<style type="text/css"> <!-- body {font-family: Verdana, Arial, sans-serif} ***set font family for entire Web page***

Lab 4 CSS CISC1600, Spring 2012

5 Snowdonia. 94 Web Applications with C#.ASP

Lab Introduction to Cascading Style Sheets

Using Dreamweaver CS6

Web Publishing Intermediate 2

Introduction to using HTML to design webpages

CSS.

GIMP WEB 2.0 MENUS. Web 2.0 Menus: Horizontal Navigation Bar

Using Dreamweaver CC. 6 Styles in Websites. Exercise 1 Linked Styles vs Embedded Styles

CS 350 COMPUTER/HUMAN INTERACTION. Lecture 6

Multimedia Systems and Technologies Lab class 6 HTML 5 + CSS 3

CSS Selectors. element selectors. .class selectors. #id selectors

Assignments (4) Assessment as per Schedule (2)

GIMP WEB 2.0 MENUS. Web 2.0 Menus: Horizontal Navigation Bar with Dynamic Background Image

GIMP WEB 2.0 MENUS. Before we begin this tutorial let s visually compare a standard navigation bar and a web 2.0 navigation bar.

CSS. Shan-Hung Wu CS, NTHU

Taking Fireworks Template and Applying it to Dreamweaver

Stamp Builder. Documentation. v1.0.0

Exam Format: Multiple Choice, True/False, Short Answer (3 points each 75 points total) Write-the-page (25 points)

Cascading Style Sheets (CSS)

<body bgcolor=" " fgcolor=" " link=" " vlink=" " alink=" "> These body attributes have now been deprecated, and should not be used in XHTML.

Creating and Building Websites

Dreamweaver: Portfolio Site

Unveiling the Basics of CSS and how it relates to the DataFlex Web Framework

Introduction to Web Design CSS Reference

Introduction to Web Design CSS Reference

Santa Tracker. Release Notes Version 1.0

HTML HTML5. DOM(Document Object Model) CSS CSS

CSS means Cascading Style Sheets. It is used to style HTML documents.

Lab 1: Introducing HTML5 and CSS3

COSC 2206 Internet Tools. CSS Cascading Style Sheets

Session 4. Style Sheets (CSS) Reading & References. A reference containing tables of CSS properties

HTML & CSS November 19, 2014

CSS CSS how to display to solve a problem External Style Sheets CSS files CSS Syntax

Web Development and HTML. Shan-Hung Wu CS, NTHU

Cascading Style Sheets Level 2

WEBSI TE DESIGNING TRAINING

Cascading Style Sheet. Styles as Tag Attributes. Syntax. <h1>: what font type/size is used? STYLE = SELECTOR {RULES} Attributes such as bgcolor

PUBLISHER SPECIFIC CSS RULES

CSS: The Basics CISC 282 September 20, 2014

Co. Louth VEC & Co. Monaghan VEC. Programme Module for. Web Authoring. leading to. Level 5 FETAC. Web Authoring 5N1910

Creating a Navigation Bar with a Rollover Effect

Zen Garden. CSS Zen Garden

CSS مفاهیم ساختار و اصول استفاده و به کارگیری

Using Dreamweaver. 6 Styles in Websites. 1. Linked or Imported Stylesheets. 2. Embedded Styles. 3. Inline Styles

CSS Styles Quick Reference Guide

CSS: formatting webpages

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

Index. alt, 38, 57 class, 86, 88, 101, 107 href, 24, 51, 57 id, 86 88, 98 overview, 37. src, 37, 57. backend, WordPress, 146, 148

Module 2 (VII): CSS [Part 4]

Networks and Web for Health Informatics (HINF 6220) Tutorial 8 : CSS. 8 Oct 2015

CSS: Layout Part 2. clear. CSS for layout and formatting: clear

Introduction to WEB PROGRAMMING

Web Information System Design No.4 Put Style to Web Documents. Tatsuya Hagino

ITNP43: HTML Lecture 4

1/6/ :28 AM Approved New Course (First Version) CS 50A Course Outline as of Fall 2014

Before you begin, make sure you have the images for these exercises saved in the location where you intend to create the Nuklear Family Website.

CMPT 165 Advanced XHTML & CSS Part 3

Introduction to CSS. Part 1: Simple Text Formatting. Source Files for this Exercise are available on the Course Website DW_CSS intro

Web Design and Development Tutorial 03

To illustrate how to set TAG styles the <body> and <h1> tags (for the BODY and the HEADING 1 styles) will be adjusted.

Hoster: openload.co - Free PLUGIN_DEFECT-Error: 08d a1830b60ab13ddec9a2ff6

Web Style Guide. May 15, 2010

Web Technologies - by G. Sreenivasulu Handout - 1 UNIT - I

LING 408/508: Computational Techniques for Linguists. Lecture 14

ICT IGCSE Practical Revision Presentation Web Authoring

Cascading Style Sheets CSCI 311

Programmazione Web a.a. 2017/2018 HTML5

Overview. Part I: Portraying the Internet as a collection of online information systems HTML/XHTML & CSS

3. Each of these mark examples contains an error. a. <input name= country value= Your country here. /> b. <checkbox name= color value= teal />

Web Designer s Reference

With HTML you can create your own Web site. This tutorial teaches you everything about HTML.

AGENDA :: MULTIMEDIA TOOLS :: (1382) :: CLASS NOTES

Study Guide 2 - HTML and CSS - Chap. 6,8,10,11,12 Name - Alexia Bernardo

Hyperlinks, Tables, Forms and Frameworks

Creating and Installing Custom Plesk for Windows Skins

CSS Cascading Style Sheets

Adding CSS to your HTML

HTML and CSS COURSE SYLLABUS

Getting your work online. behance.net cargo collective krop coroflot

Using Dreamweaver CS6

In the early days of the Web, designers just had the original 91 HTML tags to work with.

CSS exercise - Part 1

Comp-206 : Introduction to Software Systems Lecture 23. Alexandre Denault Computer Science McGill University Fall 2006

Quick Start Guide. This guide will help you get started with Kentico CMS for ASP.NET. It answers these questions:

/* ========================================================================== PROJECT STYLES

Deccansoft Software Services

Wanted! Introduction. Step 1: Styling your poster. Activity Checklist. In this project, you ll learn how to make your own poster.

Data Visualization (CIS/DSC 468)

Ministry of Higher Education and Scientific Research

ICT IGCSE Practical Revision Presentation Web Authoring

First Diploma Unit 10 Client Side Web. Week 4 CSS and Images

GIMP WEB 2.0 MENUS WEB 2.0 MENUS: HORIZONTAL NAVIGATION BAR CREATING AN HTML LIST

VCE / VET INFORMATION AND COMMUNICATION TECHNOLOGY

Session 3.1 Objectives Review the history and concepts of CSS Explore inline styles, embedded styles, and external style sheets Understand style

Web Structure and Style. MB2030 Section 2 Class 4

Transcription:

Psychology Experiments on the Web Using PHP and MySQL Lisa M. DeBruine August 14, 2008 Contents 1 Basic Web Authoring 2 1.1 Setting up your webpage....................... 2 1.2 HTML................................. 3 1.2.1 HTML Template....................... 3 1.2.2 Images............................. 4 1.2.3 Web Forms.......................... 4 1.3 CSS.................................. 6 1.3.1 Without CSS......................... 6 1.3.2 With CSS........................... 7 1.3.3 CSS Template........................ 8 1.4 JavaScript............................... 11 1.5 References............................... 11 2 PHP 12 2.1 Accessing PHP............................ 12 2.1.1 On the University Server.................. 12 2.1.2 On Your Own Computer.................. 12 2.2 Basic PHP.............................. 12 2.3 Iteration................................ 12 2.4 Functions............................... 12 2.5 Exercises............................... 12 2.5.1 Publication List....................... 12 2.5.2 Questionnaire......................... 12 2.6 References............................... 12 3 MySQL 12 3.1 Accessing MySQL.......................... 12 3.1.1 On the University Server.................. 12 3.2 Helper Files.............................. 12 3.2.1.login............................. 12 3.2.2.alias.............................. 12 1

3.2.3 On Your Own Computer.................. 13 3.3 Basic SQL............................... 13 3.4 SQL Templates............................ 13 3.5 Backing Up Your Data........................ 13 3.6 Exercises............................... 13 3.6.1 Make a Publication Database................ 13 3.6.2 Make an Experiment Database............... 13 3.7 References............................... 13 4 Integrating 14 4.0.1 Tracking Publications.................... 14 4.0.2 Creating a Publication Database.............. 14 4.0.3 Displaying database entries on your Webpage....... 14 4.0.4 Web form for editing Publication Information....... 14 4.1 Login and Registration........................ 14 4.1.1 Creating a Participant Database Table........... 14 4.1.2 Checking Passwords..................... 14 4.1.3 Recording Logins....................... 14 4.2 Questionnaires............................ 14 4.2.1 Creating a Questionnaire Database Table......... 14 4.2.2 PHP Functions for Questionnaires............. 14 4.2.3 Recording Data........................ 14 4.3 Image Preference Experiments................... 14 4.3.1 Creating an Experiment Database Table.......... 14 4.3.2 PHP Functions for Experiments.............. 14 4.3.3 JavaScript for Reaction Time................ 14 4.3.4 Recording Data........................ 14 1 Basic Web Authoring 1.1 Setting up your webpage If you do not already have a webpage, you may need to create a webpage folder. (a) directions for PCs at work (b) directions for elsewhere. 1. Go to your filespace: (a) Open the H: drive (b) (or) Open the terminal (mac) and type ssh -l psy### sysa.abdn.ac.uk or the Run command (PC) and type telnet sysa.abdn.ac.uk 2. Create a public.htm folder: (a) Make a new folder and name it public.htm (b) (or) type mkdir ~/public.htm 3. Publish the folder: 2

(a) Go to http://www.abdn.ac.uk/local/publish.htm (b) (or) type www.publish See also http://www.abdn.ac.uk/diss/webpack/factsheet10.shtml 1.2 HTML It is essential to be able to write web pages from scratch (without an HTML editor such as Dreamweaver) in order to make dynamic web pages with PHP. You can edit your web pages with any text editor. I recommend jedit (http://www.jedit.org/) for Mac and PC. 1.2.1 HTML Template <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>title TO APPEAR IN BROWSER TITLE BAR</title> <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8"> <meta name="author" content="your NAME" /> <meta name="description" content="short DESCRIPTION OF YOUR SITE" /> <link rel="shortcut icon" href="/~psy###/php_practice/images/favicon.ico"> <link rel="stylesheet" type="text/css" href="/~psy###/php_practice/include/style.css"> </head> <body> <h1>title OF PAGE</h1> <!-- MENU OF WEBPAGE --> <ul id="menu"> <li><a href="/~psy###/php_practice/">home</a></li> <li><a href=""/~psy###/php_practice/pubs/">publications</a></li> <li><a href=""/~psy###/php_practice/research/">research</a></li> </ul> <!-- CONTENTS OF WEBPAGE --> <p>paragraph OF WORDS</p> <div class="buttons"> <a href="http://www.abdn.ac.uk/psychology">aberdeen Psychology</a> </div> 3

</body> </html> 1.2.2 Images Images are fairly easy to insert into a webpage. It is good practice to keep all of your image files in a separate folder, usually named images. There are a few ways to display images. <head> <style type="text/css"> #banana { width: 135px; height: 101px; background: url(/~psy###/php_practice/images/banana.jpg) no-repeat top left; </style> </head> <body> <h2>using the img tag</h2> <img src="/~psy###/php_practice/images/banana.jpg" alt="banana" width="135" height="101" <h2>as the background of a div</h2> <div id="banana"></div> </body> 1.2.3 Web Forms Web forms are one of the main ways to collect data from your participants. There are several types of form inputs. The example below uses all of them. <form action="/~psy###/php_practice/scripts/login.php" method="post" enctype="multipart/form-data"> <ul class="formlist"> <!-- USERNAME (text input) --> <li> <label for="username">username</label> <input name="username" id="username" type="text" /> </li> <!-- PASSWORD (password input) --> <li class="shade"> <label for="password">password</label> <input name="password" id="password" type="password" /> </li> 4

<!-- SEX (radiobutton input) --> <li> <label for="sex">sex</label> <ul class="radiogroup" id="sex"> <li><input name="sex" id="male" type="radio" /> <label for="male">male</label></li> <li><input name="sex" id="female" type="radio" /> <label for="female">female</label></li> </ul> </li> <!-- YEAR (single option select input) --> <li class="shade"> <label for="year">year in school</label> <select name="year" id="year"> <option value="null"></option> <option value="1">first</option> <option value="2">second</option> <option value="3">third</option> <option value="4">fourth</option> <option value="5">postgrad</option> <option value="6">staff</option> </select> </li> <!-- PETS (multiple option select input) --> <li> <label for="pets">pets<br /> <span class="note">hold down cntl or cmd to select more than one</span> </label> <select multiple name="pets" id="pets" size="6"> <option value="none">none</option> <option value="cat">cat</option> <option value="dog">dog</option> <option value="ferrett">ferrett</option> <option value="fish">fish</option> <option value="other">other</option> </select> </li> <!-- ETHNICITY (checkbox input) --> <li class="shade"> <label for="ethnicity">ethnicity</label> <ul class="checkboxgroup" id="ethnicity"> <li><input name="euro" id="euro" type="checkbox" /> 5

<label for="euro">european</label></li> <li><input name="easian" id="easian" type="checkbox" /> <label for="easian">east Asian</label></li> <li><input name="wasian" id="wasian" type="checkbox" /> <label for="wasian">west Asian</label></li> <li><input name="african" id="african" type="checkbox" /> <label for="african">african</label></li> </ul> </li> <!-- PICTURE (file upload input) --> <li> <label for="picture">upload your picture</label> <input name="picture" id="picture" type="file" /> </li> </ul> <!-- (submit and reset buttons) --> <div class="buttons"> <input value="submit" type="submit" /> <input value="clear" type="reset" /> </div> </form> 1.3 CSS Cascading Style Sheets (CSS) are a way to organise what your webpage looks like in a way that is easy to edit and saves on loading time of your pages. You can put general CSS commands in a file that is referenced in every webpage on your site and you can put more specialised commands that may only be used on one page in the header of that page. 1.3.1 Without CSS Here is an excerpt from the Chronicle of Higher Education s advice page. Notice how the same style is applied over and over again, wasting time, bandwidth, and making it very difficult to change. <TD colspan=2 valign=top style="padding-right: 3px; border-right: 1px solid #989A9E; border-bottom: 1px solid #989A9E; background: #E0DFD4;"> <DIV style="padding-bottom: 3px; margin-bottom: 5px;" ID="newsList"> <A HREF="/news/" style="display: block; font: 8pt arial,helvetica,sans-serif; color: #294F83; margin: 3px 3px 6px 9px; padding: 0 0 3px 0; border-bottom: 1px dashed #ADABA1; text-decoration: none;"> 6

Today"s news</a> <A HREF="/chronicle/" style="display: block; font: 8pt arial,helvetica,sans-serif; color: #294F83; margin: 3px 3px 6px 9px; padding: 0 0 3px 0; border-bottom: 1px dashed #ADABA1; text-decoration: none;"> Current issue</a> <A HREF="/special/" style="display: block; font: 8pt arial,helvetica,sans-serif; color: #294F83; margin: 3px 3px 6px 9px; padding: 0 0 3px 0; border-bottom: 1px dashed #ADABA1; text-decoration: none;"> Special issues</a> <A HREF="/faculty/" style="display: block; font: 8pt arial,helvetica,sans-serif; color: #294F83; margin: 3px 3px 6px 9px; padding: 0 0 3px 0; border-bottom: 1px dashed #ADABA1; text-decoration: none;"> The Faculty</A>... (this goes on for a page)... </DIV> </TD> 1.3.2 With CSS Instead, you can turn each different style into a rule and only write it once in a separate file that will apply to every webpage on your site. Then, if you want to change the fonts for all your news list items, you just have to edit one line. /* Sample CSS for the Chronicle of Higher Education */ td.nl { padding-right: 3px; border-right: 1px solid #989A9E; border-bottom: 1px solid #989A9E; background: #E0DFD4; #newslist { padding-bottom: 3px; margin-bottom: 5px; #newslist a { display: block; font: 8pt arial,helvetica,sans-serif; color: #294F83; margin: 3px 3px 6px 9px; padding: 0 0 3px 0; border-bottom: 1px dashed #ADABA1; text-decoration: none; This is the same excerpt after converting it to use CSS. <TD colspan=2 valign=top class="nl"> 7

<DIV id="newslist"> <A HREF="/news/" >Today"s news</a> <A HREF="/chronicle/">Current issue</a> <A HREF="/special/">Special issues</a> <A HREF="/faculty/">The Faculty</A>... (this goes on for a few more lines)... </DIV> </TD> 1.3.3 CSS Template The online CSS Reference is the best source for learning about CSS. You should be able to modify the basic template below to suit your needs. /*------------------------------------------------- CSS for all pages in my php_practice webpage PAGE COLORS background: #FFF (white) text: #151515 (very dark grey) titles: #900 (dark red) highlights: #C00 (red) shading: #999 (med grey) -------------------------------------------------*/ /*------------------------------------------------- PAGE BODY -------------------------------------------------*/ /* zero the margins, paddings and borders for all elements */ * { margin: 0; padding: 0; border: 0; body { font-family: "Lucida Grande", Helvetica, Arial, sans-serif; font-size: medium; color: #151515; background-color: #FFF; margin: 0px 10% 0px 10%; h1 { font-size: 3em; font-weight: bold; text-align: center; 8

p { color: #900; text-align: left; padding: 3px; hr { clear: both; width: 100%; /***** TEXT LINKS *****/ a:link, a:visited, a:hover, a:active { text-decoration: none; border-bottom: 1px dotted #C00; a:link { color: #C00; a:visited { color: #900; a:hover, a:active { color: #FFF; background-color: #C00; /***** IMAGE LINKS *****/ a img { background-color: #FFF; border: 1px solid white; a:hover img { border: 1px solid #999; /***** BASIC LISTS *****/ ul { list-style: none; padding: 0; margin:.5em; li { background-repeat: no-repeat; background-position: 0 5px; padding: 2px 10px 2px 20px; /***** MENU *****/ #menu li { display: inline; #menu a { padding: 2px 3px; #menu a:link, #menu a:visited { border: 1px dashed #C00; background-color: #FFF; color: #C00; 9

#menu a:hover, #menu a:active, #menu a.current { background-color: #C00; color: #FFF; /***** BUTTONS *****/.buttons { padding: 6px; text-align: center; clear: both;.buttons input,.buttons a { border: 2px solid #999; background-color: #FFF; color: #000; text-align: center; padding: 3px;.buttons input:hover,.buttons a:hover,.buttons a:active { border-color: #C00; background-color: #DDD; color: #000; /***** FORMS *****/ form { width: 450px; margin: 1em auto; border: 3px solid #999; background-color: #EEE; color: #151515; padding: 10px; input, select { border: 1px dotted #C00;.shade { background-color: #EEE; label.note { font-size: 9px;.formlist { clear: both;.formlist li { clear: both; padding: 3px; 10

.formlist li>label:first-child { float: left; text-align: right; width: 35%;.formlist li input,.formlist li select,.formlist li ul { float: right; text-align: left; width: 60%; margin: 0; padding: 0;.radiogroup,.checkboxgroup { list-style: none;.formlist li.checkboxgroup *,.formlist li.radiogroup * { float: none; 1.4 JavaScript JavaScript (technically called ECMAscript) is a way to get the users computers to do work for you. While PHP is server-side scripting (your local webserver does all the work), JS is client-side scripting. Some people turn off the JS capabilities of their browser because of security issues, but most people can use sites with JS. I am not going to teach you much about JS, but we may use it in conjunction with PHP to make some things easier for users with JS turned on. I use JS in experiments to reduce the work load on the server. Without JS, participants had to run a script to generate a new webpage and download it for every trial and the server had to keep track of the random order of trials for each participant. With JS, each user s computer randomises the order of trials and just downloads the new images for each trial, instead of running a script to generate a new webpage. JS can also allow you to collect more accurate timing information for trials. 1.5 References XHTML Reference - http://www.w3schools.com/xhtml Web Forms - http://www.webstandards.org/learn/tutorials/accessible-forms CSS Reference - http://www.w3schools.com/css CSS Zen Garden - http://www.csszengarden.com Colour Scheme Generator - http://wellstyled.com/tools/colorscheme2 JavaScript Tutorial - http://www.w3schools.com/js 11

2 PHP 2.1 Accessing PHP 2.1.1 On the University Server 2.1.2 On Your Own Computer 2.2 Basic PHP 2.3 Iteration 2.4 Functions 2.5 Exercises 2.5.1 Publication List 2.5.2 Questionnaire 2.6 References PHP Reference Manual - http://uk.php.net/manual/en/ PHP Function Index (for Mac OS X) - http://www.artissoftware.com/phpfi/ 3 MySQL 3.1 Accessing MySQL 3.1.1 On the University Server 3.2 Helper Files 3.2.1.login Add the following text to your.login file: ## My Settings ## source.alias set nobeep setenv EDITOR pico 3.2.2.alias A.alias file holds all of the shortcuts you would rather not type repeatedly. Add a line that reads alias shortname command for any aliases you want to make. Make a.alias file with the following text: setenv PATH /local/bin/mysql:$path 12

alias dbname mysql -h mysql.abdn.ac.uk -u psy###_dbname -p****** psy###_dbname alias dump_dbname mysqldump -h mysql.abdn.ac.uk -u psy###_dbname -p****** psy###_dbname 3.2.3 On Your Own Computer 3.3 Basic SQL 3.4 SQL Templates 3.5 Backing Up Your Data 3.6 Exercises 3.6.1 Make a Publication Database 3.6.2 Make an Experiment Database 3.7 References MySQL Reference Manual - http://dev.mysql.com/doc/mysql/en/index.html 13

4 Integrating 4.0.1 Tracking Publications 4.0.2 Creating a Publication Database 4.0.3 Displaying database entries on your Webpage 4.0.4 Web form for editing Publication Information 4.1 Login and Registration 4.1.1 Creating a Participant Database Table 4.1.2 Checking Passwords 4.1.3 Recording Logins 4.2 Questionnaires 4.2.1 Creating a Questionnaire Database Table 4.2.2 PHP Functions for Questionnaires 4.2.3 Recording Data 4.3 Image Preference Experiments 4.3.1 Creating an Experiment Database Table 4.3.2 PHP Functions for Experiments 4.3.3 JavaScript for Reaction Time 4.3.4 Recording Data 14