lecture 27 connections: a web application · 2018-01-08 · connections: a web application mr....

31
CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) [email protected] 1 Lecture 27

Upload: others

Post on 13-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

CONNECTIONS: A Web Application

Mr. Mubashir AliLecturer (Dept. of Computer Science)

[email protected]

1

Lecture 27

Page 2: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

Summary of the previous lecture

• Deleting records in MySQL using PHP

• Updating records in MySQL using PHP

Mubashir Ali - Lecturer (Department of Computer Science).

2

Page 3: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

Outline

• User registration (already discussed)

• User login (already discussed)

• Send Message

• Inbox

• Out Box

• Sign-Out

Mubashir Ali - Lecturer (Department of Computer Science).

3

Page 4: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

1. User registration

• User registration form:

– Home page

• Action page:

– Retrieve user’s input

– Validate input

– Connection with DB

– Insert record into users table

Mubashir Ali - Lecturer (Department of Computer Science).

4

Page 5: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

2. User login

• User login form:

– Home page

• Action page:

– Retrieve user’s input

– Connection with DB

– Select record from users table where user email and password are same as user’s input

Mubashir Ali - Lecturer (Department of Computer Science).

5

Page 6: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

2. User login…

• If one row is selected then:

– Session variables are registered

• $_SESSION[‘name’];

• $_SESSION[‘email’];

• $_SESSION[‘password’];

– Redirect to user’s page

• Redirect to index page with error message

Mubashir Ali - Lecturer (Department of Computer Science).

6

Page 7: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

3. Send message

• Create a table in connections database as:

– Table Name: messages

– No. of fields: 4

• message_Id int 5

• s_Email varchar 50

• r_Email varchar 50

• message varchar 500

Mubashir Ali - Lecturer (Department of Computer Science).

7

Page 8: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

3. Send message…

Mubashir Ali - Lecturer (Department of Computer Science).

8

Table fields

Page 9: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

3. Send message…

Mubashir Ali - Lecturer (Department of Computer Science).

9

• Form to send message:– Receiver email: data-list of users

– Message: text-area

– Submit button

• Action page:– Retrieve receiver email and message from post

array

– Retrieve sender email from $_SEESION[‘email’]

– Insert data into messages table

Page 10: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

3. Send message…

Mubashir Ali - Lecturer (Department of Computer Science).

10

Session starts

DB connection

HTML page starts

Page 11: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

3. Send message…

Mubashir Ali - Lecturer (Department of Computer Science).

11

header

links

Page 12: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

3. Send message…

Mubashir Ali - Lecturer (Department of Computer Science).

12

Form starts

First row shows the message from action page

Page 13: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

3. Send message…

Mubashir Ali - Lecturer (Department of Computer Science).

13

List attribute

Input field

Datalist starts

Selects users

Loop starts

Sets options Loop ends

Datalist ends

Page 14: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

3. Send message…

Mubashir Ali - Lecturer (Department of Computer Science).

14

Textarea for message

Submit button

Form ends

Page 15: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

3. Send message…

Mubashir Ali - Lecturer (Department of Computer Science).

15

Footer div

Page 16: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

3. Send message…

Mubashir Ali - Lecturer (Department of Computer Science).

16

header

actions

form

footer

Page 17: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

3. Send message…

Mubashir Ali - Lecturer (Department of Computer Science).

17

Session starts Sender’s email from session

User’s input

DB Connection

Insertion Instruction

Query executedredirection

Page 18: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

4. Inbox page

• Session starts

• DB connection

• Retrieve receiver id from session

• Select messages against user’s id

• Display structure

• Display all messages

Mubashir Ali - Lecturer (Department of Computer Science).

18

Page 19: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

4. Inbox page

Mubashir Ali - Lecturer (Department of Computer Science).

19

Session starts

DB connection

CSS is included

Page 20: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

4. Inbox page…

Mubashir Ali - Lecturer (Department of Computer Science).

20

Header and logo

Action box

Page 21: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

4. Inbox page…

Mubashir Ali - Lecturer (Department of Computer Science).

21

User’s id

Messages received by user

Instruction executed

Message is fetched

Sender’s information

Page 22: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

4. Inbox page…

Mubashir Ali - Lecturer (Department of Computer Science).

22

Sender’s picture

Sender’s email

messageLoop ends

Footer

Page 23: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

4. Inbox page…

Mubashir Ali - Lecturer (Department of Computer Science).

23

Sender pic

message

Page 24: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

5. Outbox page

• Session starts

• DB connection

• Retrieve receiver id from session

• Select messages sent against user’s id

• Display structure

• Display all messages

Mubashir Ali - Lecturer (Department of Computer Science).

24

Page 25: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

5. Outbox page…

Mubashir Ali - Lecturer (Department of Computer Science).

25

Messages sent by the user

Messages are fetchedReceiver’s info

Page 26: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

5. Outbox page…

Mubashir Ali - Lecturer (Department of Computer Science).

26

Messages are displayed

Page 27: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

5. Outbox page…

Mubashir Ali - Lecturer (Department of Computer Science).

27

Page 28: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

6. Sign-Out

Mubashir Ali - Lecturer (Department of Computer Science).

28

• Starts session

• Destroy session

• Redirect

Page 29: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

6. Sign-Out…

Mubashir Ali - Lecturer (Department of Computer Science).

29

Session starts

Session destroys

redirection

Page 30: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

Summary

• User registration (already discussed)

• User login (already discussed)

• Send Message

• Inbox

• Out Box

• Sign-Out

Mubashir Ali - Lecturer (Department of Computer Science).

30

Page 31: Lecture 27 CONNECTIONS: A Web Application · 2018-01-08 · CONNECTIONS: A Web Application Mr. Mubashir Ali Lecturer (Dept. of Computer Science) dr.mubashirali1@gmail.com 1 Lecture

References

• Chapter 30, “Beginning PHP and MySQL” by W. Jason Gilmore, Apress publisher, 4th edition; 2010, ISBN-13 (electronic): 978-1-4302-3115-8.

Mubashir Ali - Lecturer (Department of Computer Science).

31