dynamic web pages ch 9 v1.0

24
Chapter 9 Chapter 9 Using Session variables, Using Session variables, hidden fields & inserting hidden fields & inserting data. data.

Upload: cathie101

Post on 18-Jan-2015

377 views

Category:

Technology


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Dynamic Web Pages Ch 9 V1.0

Chapter 9Chapter 9Chapter 9Chapter 9

Using Session variables, hidden Using Session variables, hidden fields & inserting data.fields & inserting data.

Page 2: Dynamic Web Pages Ch 9 V1.0

Overview• In this chapter you will

– Create restricted administration pages.

– Use Session variables– Use hidden fields– Insert records into a table.

Page 3: Dynamic Web Pages Ch 9 V1.0

Creating an Insert Journal Pg -1

Open the generic_template.php.

Save as journalAdd.php.

Change the page as shown above.

Page 4: Dynamic Web Pages Ch 9 V1.0

Insert a record

• On the journalAdd.php page and select the “Insert Record” as shown.

• The next slide shows the screen that appears.

Page 5: Dynamic Web Pages Ch 9 V1.0

Inserting a record

• Notice that the JournalID field needs a value. • This value needs to be increased by one.

– Eg: last value is 3 the next value needs to be 4.

Page 6: Dynamic Web Pages Ch 9 V1.0

Adding a recordset to find the id value

• Create this recordset to find the largest number.

Page 7: Dynamic Web Pages Ch 9 V1.0

Creating a new journal ID

• Find the recordset code as shown above.

• Add lines 61 & 62.• These lines obtain the highest id

and add one to it.

Page 8: Dynamic Web Pages Ch 9 V1.0

Storing the id in the form.• Add a hidden

textfield in the form as shown.

• Write the value as shown. This is the value of the new id that was calculated at the top of the page on the previous slide.

Page 9: Dynamic Web Pages Ch 9 V1.0

Placing the insert record script

• Double click on the insert record made earlier and add the new id as the journalID.

Page 10: Dynamic Web Pages Ch 9 V1.0

Session VariablesSession VariablesSession VariablesSession Variables

Page 11: Dynamic Web Pages Ch 9 V1.0

Creating a Session variable• Create a basic page as shown with

a textfield and button in a form.

• Create a new page and call it createsession.php.

• Link the form to the createsession.php page.

Page 12: Dynamic Web Pages Ch 9 V1.0

Creating a Session variable - 2

• To create a session variable the session_start() function must be the 1st line in the document.

• Then declare and initialise the variable as shown below. Post from the page before.

Page 13: Dynamic Web Pages Ch 9 V1.0

Creating a Session variable - 3

• Create the page below, starting the session and then displaying it.

• Create a link on the createsession.php to this page. This is show on the previous slides.

Page 14: Dynamic Web Pages Ch 9 V1.0

Classes in phpClasses in phpClasses in phpClasses in php

Page 15: Dynamic Web Pages Ch 9 V1.0

Creating A Class

• Classes are similar to Java and actionscript.• A class has a constructor or a default on is added

at compilation time.• Below is the start of a person class.• This class is to hold the info about the people that

log into the following pages.Name of the class and file name must be identical.

Declaring variables.

Constructor must be identical to the class name.

Page 16: Dynamic Web Pages Ch 9 V1.0

Creating a Class -2• The gets and

the sets.• The close of

the class• The close of

the php tag.

Page 17: Dynamic Web Pages Ch 9 V1.0

Using the class to store variables

• The next couple of slides show the code to create a session variable so it can store an array of objects.

• These objects are created using the Person class.

Page 18: Dynamic Web Pages Ch 9 V1.0

Using the class to store variables-2

• A login page to start the session variable.

Page 19: Dynamic Web Pages Ch 9 V1.0

Using the class to store variables-3

• The design view of the add people page.

Page 20: Dynamic Web Pages Ch 9 V1.0

Using the class to store variables-4

• The php code. The include statement allows access to the Person class.

Page 21: Dynamic Web Pages Ch 9 V1.0

Using the class to store variables-5

• The html code on the page.

Page 22: Dynamic Web Pages Ch 9 V1.0

Using the class to store variables-6

• How to view the data in the class.

Page 23: Dynamic Web Pages Ch 9 V1.0

Using the class to store variables-7

Table headings.

Obtaining the number of objects in the array.

Getting each variable for each object.

Placing each variable in the table

Page 24: Dynamic Web Pages Ch 9 V1.0

Using the class to store variables-8

• These files can be found a zipped folder called classes.zip on myChisholm.