Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the...

15
http://www.cse.msu.edu/ http://www.cse.msu.edu/ ~cse103 ~cse103 U:/msu/course/cse/103 U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 1 Back-up PHP Files Back-up PHP Files If you have not yet passed If you have not yet passed the 3.0 BT, make back-up the 3.0 BT, make back-up copies of ALL of your PHP copies of ALL of your PHP files (BEFORE you start files (BEFORE you start today’s class work) to use today’s class work) to use when you take the 3.0 BT. when you take the 3.0 BT. What we cover today may What we cover today may complicate taking the BT if complicate taking the BT if you try to use it then you try to use it then

Transcript of Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the...

Page 1: Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 11

Back-up PHP FilesBack-up PHP Files

If you have not yet passed the 3.0 If you have not yet passed the 3.0 BT, make back-up copies of ALL BT, make back-up copies of ALL of your PHP files (BEFORE you of your PHP files (BEFORE you start today’s class work) to use start today’s class work) to use when you take the 3.0 BT.when you take the 3.0 BT.–What we cover today may What we cover today may

complicate taking the BT if you try complicate taking the BT if you try to use it thento use it then

Page 2: Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 22

Review of Day 23Review of Day 23

Create a form page, Create a form page, addmovie_form.phpaddmovie_form.php that that has text boxes for the title and yearhas text boxes for the title and year

Create a handler page Create a handler page addmovie_handler.phpaddmovie_handler.php – Write SQL query to add title and year to Write SQL query to add title and year to tbl_Moviestbl_Movies

INSERT INTO tbl_Movies (MovieTitle, Year) VALUES INSERT INTO tbl_Movies (MovieTitle, Year) VALUES ('('valueForMovieTitle', valueForYearvalueForMovieTitle', valueForYear))

– Use form information via $_POST[‘Use form information via $_POST[‘NameName’], where ’], where NameName is the is the name=name= of the form of the form <input><input> element element

– Use Use insert_autonumbered_row()insert_autonumbered_row() to submit the query to submit the query– Save new id returned by function in new PHP variableSave new id returned by function in new PHP variable

Page 3: Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 33

Review of Day 23 continuedReview of Day 23 continued

Add a form element for entry of Genre Add a form element for entry of Genre data to the data to the addmovie_form.phpaddmovie_form.php page. page. Make this form element a drop-down box.Make this form element a drop-down box.– Use only Genres listed in Use only Genres listed in tbl_Genrestbl_Genres– Use Use printprint and the CSE 103 support function and the CSE 103 support function

dropbox_from_query() dropbox_from_query() to make the dropbox to make the dropbox on the form. (Don’t use a normal form on the form. (Don’t use a normal form element!)element!)

Requires a query that selects two fields: one a key Requires a query that selects two fields: one a key value and one something to be displayedvalue and one something to be displayed

Page 4: Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 44

Review of Day 23, part 3Review of Day 23, part 3

Change the Change the addmovie_handler.phpaddmovie_handler.php page to also page to also add the genre information to the database.add the genre information to the database.– Assign the autonumber ID (created when title and Assign the autonumber ID (created when title and

year are added to year are added to tbl_Moviestbl_Movies) to a variable.) to a variable.– Use that variable in constructing a query to add the Use that variable in constructing a query to add the

movieID and the submitted genre info (and rank 1) to movieID and the submitted genre info (and rank 1) to tbl_MovieGenrestbl_MovieGenres

The $_POST['The $_POST['namename'] for this matches the 2'] for this matches the 2ndnd argument to argument to dropbox_from_query()dropbox_from_query() on your form page on your form page

– Use the CSE 103 support function Use the CSE 103 support function run_action_query() run_action_query() to run this query.to run this query.

Page 5: Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 55

Adding Movies ConsiderationsAdding Movies Considerations

Q1: How can we determine if the “add” is Q1: How can we determine if the “add” is successful?successful?

Q2: How can we determine if a movie is in Q2: How can we determine if a movie is in the database already?the database already?

Q3: What should we do if a movie is Q3: What should we do if a movie is already in the database? already in the database?

Page 6: Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 66

A1: The IF statementA1: The IF statement

TheThe IF IF statement lets us perform one or another statement lets us perform one or another set of actions based on the value of a test.set of actions based on the value of a test.– The test must have a value of either The test must have a value of either truetrue or or falsefalse..

– It uses relational operators <, >,<>,==, etc.It uses relational operators <, >,<>,==, etc.

If If true,true, the first set of statements after the IF are the first set of statements after the IF are executed.executed.

If If false,false, the statements after an the statements after an elseelse (following (following the if) are performed instead.the if) are performed instead.

Page 7: Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 77

Example: IF testExample: IF test

ifif (( $MovieID $MovieID ==== 00)) { {

printprint "No movie added"; "No movie added";

}}

elseelse { {

printprint "Movie added with ID = "; "Movie added with ID = ";

printprint $MovieID; $MovieID;

}}

Autonumber IDs are never 0, so if 0 was Autonumber IDs are never 0, so if 0 was returned, we know we didn't get a "real" IDreturned, we know we didn't get a "real" ID

Page 8: Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 88

First Conditional ExerciseFirst Conditional Exercise

Modify your Modify your addmovie_handler.phpaddmovie_handler.php page page to test whether or not the action query on to test whether or not the action query on tbl_Moviestbl_Movies is successful is successful– What does it mean that a movie was added?What does it mean that a movie was added?

Display appropriate messages to the user Display appropriate messages to the user and take other appropriate actions in each and take other appropriate actions in each case. case. – What should you do if adding the record is What should you do if adding the record is

successful? … if it is not successful?successful? … if it is not successful?

Page 9: Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 99

A2 & A3: Check for a pre-A2 & A3: Check for a pre-existing entry and actionexisting entry and action

Write an SQL query to test whether or not a Write an SQL query to test whether or not a MovieTitleMovieTitle and and YearYear combination is already in the combination is already in the database.database.– What can we look for that we can easily test?What can we look for that we can easily test?

Use the returned value in an IF testUse the returned value in an IF test– How should we test? What does our test mean if true?How should we test? What does our test mean if true?

If the movie If the movie IS NOTIS NOT in the database, then add it in the database, then add it as a new record and continue as before.as a new record and continue as before.If the movie If the movie ISIS in the database, display a in the database, display a message to that effect plus its message to that effect plus its MovieIDMovieID..– STOP and do not attempt to insert the dataSTOP and do not attempt to insert the data

Page 10: Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 1010

Dynamic Web Page DesignDynamic Web Page Design

How should I put dynamic pages together How should I put dynamic pages together to form a site?to form a site?– Organization chart is very helpful, as used in Organization chart is very helpful, as used in

CSE 101CSE 101

What information is needed to construct What information is needed to construct each page?each page?

What interface do I want to present to the What interface do I want to present to the user?user?

Page 11: Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 1111

End-of-Term SIRSEnd-of-Term SIRS

Link on the Student Site Map Link on the Student Site Map

Three forms – Course, Lead , and AsstThree forms – Course, Lead , and Asst

Comments Comments willwill be considered for future be considered for future course development of CSE 101course development of CSE 101

Available until Thursday, April 28th at Available until Thursday, April 28th at 4pm, when UBTs are due4pm, when UBTs are due

Necessary to access your BT FeedbackNecessary to access your BT Feedback

Page 12: Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 1212

UBT DatabasesUBT Databases

Each student in CSE 103 currently has a Each student in CSE 103 currently has a MySQL databaseMySQL database

Database name is student’s msuNetIDDatabase name is student’s msuNetID

Database is currently empty unless you Database is currently empty unless you already submitted an Access database for already submitted an Access database for us to convertus to convert

Page 13: Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 1313

To create UBT Databases:To create UBT Databases:

You submit (via e-mail) an Access db file to You submit (via e-mail) an Access db file to [email protected]@cse.msu.edu with desired table with desired table structures (fieldnames and datatypes)structures (fieldnames and datatypes)– Also look for other properties like Required?Also look for other properties like Required?– Don't bother with lookups; we can't convert thoseDon't bother with lookups; we can't convert those– DO bother with relationships (helps us understand)DO bother with relationships (helps us understand)

We will create the tables in your db from your We will create the tables in your db from your Access sample.Access sample.You create the web forms and action pages to You create the web forms and action pages to enter data into those tables and to manipulate enter data into those tables and to manipulate the data as needed for your UBT project.the data as needed for your UBT project.

Page 14: Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 1414

A good UBT should:A good UBT should:

Demonstrate good database designDemonstrate good database design– Appropriate tables, fields, datatypes, keys, and Appropriate tables, fields, datatypes, keys, and

relationships, as well as integrity and minimal relationships, as well as integrity and minimal redundancy (everything related to the 2.0 BT)redundancy (everything related to the 2.0 BT)

Demonstrate mastery of various queriesDemonstrate mastery of various queries– Both Select and Action, use of functions, calculated Both Select and Action, use of functions, calculated

fields, aggregate functions, etc.fields, aggregate functions, etc.

Demonstrate ability to learn new conceptsDemonstrate ability to learn new concepts– Use new functions, query types, etc. that we didn’t Use new functions, query types, etc. that we didn’t

cover in-class or on any BTcover in-class or on any BT

Page 15: Http://cse103 U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 25, Slide Day 25, Slide 1515

Remainder of SemesterRemainder of Semester

Day 26 (Thurs/Mon) - In-Class BT OpportunityDay 26 (Thurs/Mon) - In-Class BT OpportunityDay 27 (next Tue/Wed) - In-Class HelproomDay 27 (next Tue/Wed) - In-Class HelproomDay 28 (next Thurs/week from Mon) - In-Class Day 28 (next Thurs/week from Mon) - In-Class BT OpportunityBT OpportunityThursday, April 28Thursday, April 28thth - UBTs due at 4 pm - UBTs due at 4 pmOn Days 26 and 28, your Lead will be in the On Days 26 and 28, your Lead will be in the CSE 103 office during class hours if you have CSE 103 office during class hours if you have already passed 3.0 and need UBT help already passed 3.0 and need UBT help Feel free to e-mail with UBT questions when Feel free to e-mail with UBT questions when workingworking