Presentation is loading. Please wait.

Presentation is loading. Please wait.

NMD202 Web Scripting Week3. What we will cover today Assignment 1 Email Database Concepts MySQL Exercises Server side validation Exercises.

Similar presentations


Presentation on theme: "NMD202 Web Scripting Week3. What we will cover today Assignment 1 Email Database Concepts MySQL Exercises Server side validation Exercises."— Presentation transcript:

1 NMD202 Web Scripting Week3

2 What we will cover today Assignment 1 Email Database Concepts MySQL Exercises Server side validation Exercises

3 Assignment 1 Milestone 1 – due week 5 Project Brief – What do you pretend to do Data Model – ER Diagram must be submitted in a VISIO file

4 Assignment 1 Examples of what you can do: Budget tracker Mini-Blog Address Book Event Planner 3 tables at least

5 Email PHP Can connect to a mail transfer agent to send emails. Mail settings are configured in the php.ini file. linux mail can be used (ie:postfix or sendmail) or you can use SMTP (platform independent)

6 Email Send mail: mail function: mail ($to,$subject,$message); This is the basic usage of mail, often you need to set headers as well.

7 Email Setting Headers: <?php $to = 'nobody@example.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com'. "\r\n". 'Reply-To: webmaster@example.com'. "\r\n". 'X-Mailer: PHP/'. phpversion(); mail($to, $subject, $message, $headers); ?>

8 Email Multiple lines in the message: <?php $message = “ Hello \n\r This is another line \n\r This is the third line \n\r ”; ?>

9 Email It is also possible to send html email: <?php $message = “ Hello ”; $headers = 'Content-type: text/html; charset=iso-8859-1'. "\r\n"; ?> Check http://au2.php.net/manual/en/function.mail.php

10 Email PHP mail function is cumbersome, the php community has developed better solutions: LibMail HTML Mime Mail

11 Email PHP mail function is cumbersome, the php community has developed better solutions: LibMail HTML Mime mail Allow: Send multiple attachments, receipts, etc...

12 Email Security Considerations: Sanitize user inputs before sending mail: Header injection Multiple recipient injection Avoid using mail function unless you know what you are doing

13 Email Some email applications tag emails sent from php as Spam if headers are not properly setup, ie:Yahoo, Google. If you targeting clients that use these emails you need to tweak the headers.

14 Database Concepts A Database is a structured collection of data Usually databases are relational: The basic data structure of the relational model is a table where information about a particular entity (say, an employee) is represented in columns and rows columns enumerate the various attributes of an entity They obey to strict rules such as: a table cannot contain 2 identical rows.

15 Database Concepts

16 Anomalies: logical or structural problems in the data model Database normalization: Fixing anomalies, Normal forms (1nf, 2nf, 3nf)

17 Database Concepts

18 http://www.geekgirls.com/databases_from_scratch_3.htm

19 Exercise: Normalize the following Table: StudentEmailSubject Name Subject Description Ass 1 Grade Ass 2 Grade Exam Grade Luis luis@as.com Maths1Initial Maths12 Luis luis@as.com Maths1Initial Maths14 Peter peter@as.co m Web Script PHP, javascript 15 Peter peter@as.co m Maths111215

20 MySQL Relational Database System – Query language ANSI SQL 99 Different type of tables: ISAM, InnoDB, etc. ISAM – fast, but does not enforce referential integrity. (default) InnoBD – enforces referential integrity, only available in MySQL v4+

21 MySQL Commands: show databases; - display all available databases use #database; - sets the current database show tables;-display all tables from current database describe #table;-display table information create... – create table drop...- delete table/database alter #table... – update a table structure Insert into... – inserts data into a table update #table set... – update data from a table Select... from #table where... – query database

22 MySQL Create Statement: CREATE DATABASE sampleDatabase; USE sampleDatabase; CREATE TABLE example( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30), age INT );

23 MySQL Create Statement: CREATE DATABASE sampleDatabase; USE sampleDatabase; CREATE TABLE example( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30), age INT );

24 MySQL Insert Statement: INSERT INTO example (name,age) VALUES (‘Luis’,12); INSERT INTO example (name,age) VALUES (‘Peter’,13); INSERT INTO example (name,age) VALUES (‘John’,26); INSERT INTO example (name,age) VALUES (‘Kim’,78); INSERT INTO example (name,age) VALUES (‘Peter’,45);

25 MySQL Query Database: SELECT name,age FROM example; Or SELECT * FROM example WHERE name=‘Peter’;

26 MySQL Update Database: UPDATE example SET name=‘Ryan’, age = 35 WHERE id=2;

27 MySQL Using MySQL: Start MySQL Server From the command prompt go to: C:\temp\xampp\mysql\bin Start the client: mysql –u root

28 MySQL Keep your commands in scite in case you need to redo them. (it is easy to drop a table and start again instead of using the ALTER statement). Make sure all commands are terminated with a semicolon ‘;’

29 MySQL After you finished either keep your scite file with all your commands or do an sql dump of your work, run from the dos prompt (inside mysql bin folder) mysqldump --databases [databasename] -u root >[backupfile.sql] In our example: mysqldump --databases sampleDatabase -u root > backup.sql

30 MySQL To Restore the database: mysql -u root < [backupfile.sql] In our example: mysql -u root < back.sql

31 Exercise: Create the data model that you normalized in your previous exercise Insert some more records into the tables (students, subjects and grades) Update all Luis grades to 100 Delete all peter records Backup your database, send me the dump by email


Download ppt "NMD202 Web Scripting Week3. What we will cover today Assignment 1 Email Database Concepts MySQL Exercises Server side validation Exercises."

Similar presentations


Ads by Google