section: pset7

21
Section: Pset7 Jordan Jozwiak CS50

Upload: charlize-vaughn

Post on 01-Jan-2016

68 views

Category:

Documents


2 download

DESCRIPTION

CS50. Section: Pset7. Jordan Jozwiak. Announcements. Section was cancelled last week due to Hurricane Sandy! Make-up lecture was filmed on Friday Pre-proposals were due at noon today! Pset6 will be returned by Tuesday night Still looking for a final project partner? - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Section: Pset7

Section: Pset7Jordan Jozwiak

CS50

Page 2: Section: Pset7

AnnouncementsSection was cancelled last week due to

Hurricane Sandy!Make-up lecture was filmed on FridayPre-proposals were due at noon today!Pset6 will be returned by Tuesday night Still looking for a final project partner?

Cs50.net/partners/formCs50.net/partners/spreadsheet

Don’t forget to add music to our coding playlist!

Page 3: Section: Pset7

This WeekThe internet … a whole new world

HTMLchmodPHPmySQL

Section of Questions

Page 4: Section: Pset7

HTMLHyperText Markup LanguageUsed to format contents of web pages.NOT a programming language

<!DOCTYPE html><html>

<body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body></html>

Page 5: Section: Pset7

HTML‘Tags’ enclose regions of page.

<html><body><h1> , <h2>, <h3>, <p>, <br/><image>, <table>, etc.

Tags may have attributesForms allow input of different types on a webpage, such

as checkboxes, radio buttons, text boxes and submit buttonsInformation from forms may be submitted and sent to

another page for use (this is usually where PHP comes in)

Page 6: Section: Pset7

CSSCSS: Cascading Style SheetsAllows for easier formatting of HTMLSpecifically formats different types of

elementsMay be included in separate file or in-lined

(what are the advantages and disadvantages of each approach?)

body{

background-color:#d0e4fe;}h1{

color:orange;text-align:center;

}

Page 7: Section: Pset7
Page 8: Section: Pset7

chmodAbbreviate from “change mode”Command-line function for controlling ‘read’,

‘write’ and ‘execute’ permission to User, Group and World

Can use octal values directly, e.g.: chmod 644 index.html

Sets permissions so only owner can read and write to the file; and everyone else can only read it

chmod 600 helpers.php Only owner can read, write and execute

Page 9: Section: Pset7

chmod

# Permission rwx

7 full 111

6 read and write 110

5 read and execute 101

4 read only 100

3 write and execute 011

2 write only 010

1 execute only 001

0 none 000

Page 10: Section: Pset7

chmod644 for non-PHP files600 for PHP files711 for directories

Page 11: Section: Pset7

PHPPHP: PHP Hypertext Preprocessor

When accessed, dynamically generates a webpage which it then outputs to browser.

PHP code is executed by the server, not by the browser

PHP code enclosed in <?php ?> tags

All PHP variables are prefaced by a $. You do NOT declare variables with a type

Page 12: Section: Pset7

PHP

Compile with clang, then run executable.

Each variable is declared with a type, and you cannot (without casting) mix and match data types, e.g.:

int a = 3;char *s = "hello"; s = s + a; // won’t compiled

C PHPCompiled InterpretedStrongly-typed

Loosely-typed

• Doesn’t get compiled; whole program is (generally) interpreted line by line

• Variables don’t have types, and you can do weird mixings of data types, e.g.:

$a = 3;$s = "hello"; $s = $s . $a; // gives "hello 3"

Page 13: Section: Pset7

PHPSingle quotes vs. Double quotes

‘this is a string’“This is also a string!\n”

Printing outputecho “hello”print “hello”<?= “hello” ?>

Page 14: Section: Pset7

PHP – foreach!

foreach (array_expression as $value) statement

foreach (array_expression as $key => $value) statement

foreach (array_expression as $value) statement foreach (array_expression as $key => $value) statement

$arr = array(1, 2, 3, 4);foreach ($arr as $value) {     echo $value;}

$arr = array(    "one" => 1,    "two" => 2,    "three" => 3,    "seventeen" => 17);

foreach ($arr as $key => $value) {    echo "$key: $value\n";}

Page 15: Section: Pset7

PHP Joke

Page 16: Section: Pset7

MySQLSQL – Structured Query Language

Database software which allows us to store a collection of data as ‘entries’ containing a set of distinct ‘fields’ containing values.

Databases contains tables, which contain rows, which contain fields.

Page 17: Section: Pset7

MySQL QueriesINSERT

Insert a new entry.DELETE

Remove an existing entry.SELECT

Select one or more entries.UPDATE

Update the fields of an existing entry.

Page 18: Section: Pset7

MySQLWARNING: It is always important to ‘escape’

the contents of any string passed by the user which is to be included in a database query.

"INSERT INTO students VALUE ('<user string');"

What could possibly go wrong?

Page 19: Section: Pset7

MySQL

Page 20: Section: Pset7

Coding time!!!Use the Appliance

dynamic.php (~7 min)unique.php (~28 min)concentrations.php (~25min)

wget http://cdn.cs50.net/2012/fall/sections/9/section9/concentrations.txt

Functions to consideris_readable(), file(), chop()

Page 21: Section: Pset7

On your way out…Remember that you can access section

powerpoints and SOQ solutions at http://cloud.cs50.net/~jjozwiak/

Check out some database examples from last year at http://cloud.cs50.net/~jjozwiak/source_code/we

ek8.ziphttp

://cloud.cs50.net/~jjozwiak/section/week8/index.html