dynamic web pages ch 9 v1.0

Post on 18-Jan-2015

377 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

Chapter 9Chapter 9Chapter 9Chapter 9

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

Overview• In this chapter you will

– Create restricted administration pages.

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

Creating an Insert Journal Pg -1

Open the generic_template.php.

Save as journalAdd.php.

Change the page as shown above.

Insert a record

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

• The next slide shows the screen that appears.

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.

Adding a recordset to find the id value

• Create this recordset to find the largest number.

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.

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.

Placing the insert record script

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

Session VariablesSession VariablesSession VariablesSession Variables

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.

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.

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.

Classes in phpClasses in phpClasses in phpClasses in php

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.

Creating a Class -2• The gets and

the sets.• The close of

the class• The close of

the php tag.

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.

Using the class to store variables-2

• A login page to start the session variable.

Using the class to store variables-3

• The design view of the add people page.

Using the class to store variables-4

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

Using the class to store variables-5

• The html code on the page.

Using the class to store variables-6

• How to view the data in the class.

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

Using the class to store variables-8

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

top related