Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Systems Development (CSC-215)

Similar presentations


Presentation on theme: "Web Systems Development (CSC-215)"— Presentation transcript:

1 Web Systems Development (CSC-215)
Lecture 7: Working with Databases

2 localhost/phpMyAdmin

3 phpMyAdmin on Remote Host

4 Set up sample database

5 Set up sample database

6 Add sample entry

7 Confirmation of entry

8 Confirmation of entry

9 Process Connect to MySQL Select the database to use
Build a query string Perform the query Retrieve results and output to a web page Repeat 3-5 until all desired data has been retrieved Disconnect from MySQL

10 Standard (Deprecated) vs. MySQLi
If you’re looking up tutorials, make sure to use MySQLi as covered in the lecture The textbook includes deprecated version of the same code as well for reference

11 Creating a Login File

12 Connecting to MySQL Server

13 Building and executing a query

14 Fetch Result

15

16 fetch_array() Can return 3 types of arrays MYSQLI_NUM MYSQLI_ASSOC
Numeric, columns appear in the array in the order defined in the table MYSQLI_ASSOC Associative, each key refers to a column (by name) MYSQLI_BOTH Associative and numeric array

17 Example

18 Make connection

19 Deleting a record

20 Inserting a record

21 Create input form

22 Get all entries

23 Display all entries

24 Close

25 Sanitize

26 End of example

27 SQL Injection User verification code

28 Preventing SQL Injection
Normal usage

29 Preventing SQL Injection
Entry for user field

30 Deletion Example

31 PHP’s Magic Quotes Feature
Automatically adds back slash to characters like single and double quotes Bypass and use mysql_real_escape_string()

32 Solution Disable special characters by prepending slashes using real_escape_string()

33 Preventing HTML Injection
Example of maliciously inserted code, via, e.g., a form that displays its input XSS: Cross-Site Scripting

34 Use htmlentities() to convert

35 Embedding PHP in HTML

36 Document head

37 Setting up table

38 Set up calculation

39 Class Activity Set up a script that is similar to the Fibonacci one but instead of Fibonacci numbers, calculate the sum to n for each number S0 = 0 S1 = = 1 S2 = = 3 S4 = = 6 S5 = = 10 Print only two columns, Sn and the sum Set different colors for alternating rows

40 Lecture content adapted from chapter 10 of Learning PHP, MySQL, JavaScript, CSS & HTML5.


Download ppt "Web Systems Development (CSC-215)"

Similar presentations


Ads by Google