150 likes | 162 Views
Learn how to back up PHP files before taking the 3.0 BT and manage databases effectively for your web development projects. Detailed instructions provided with examples and explanations.
E N D
Back-up PHP Files • If you have not yet passed the 3.0 BT, make back-up copies of ALL of your PHP files (BEFORE you start today’s class work) to use when you take the 3.0 BT. • What we cover today may complicate taking the BT if you try to use it then http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103
Review of Day 23 • Create a form page, addmovie_form.php that has text boxes for the title and year • Create a handler page addmovie_handler.php • Write SQL query to add title and year to tbl_Movies • INSERT INTO tbl_Movies (MovieTitle, Year) VALUES ('valueForMovieTitle', valueForYear) • Use form information via $_POST[‘Name’], where Name is the name= of the form <input> element • Use insert_autonumbered_row() to submit the query • Save new id returned by function in new PHP variable http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103
Review of Day 23 continued • Add a form element for entry of Genre data to the addmovie_form.php page. Make this form element a drop-down box. • Use only Genres listed in tbl_Genres • Use print and the CSE 103 support function dropbox_from_query() to make the dropbox on the form. (Don’t use a normal form element!) • Requires a query that selects two fields: one a key value and one something to be displayed http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103
Review of Day 23, part 3 • Change the addmovie_handler.php page to also add the genre information to the database. • Assign the autonumber ID (created when title and year are added to tbl_Movies) to a variable. • Use that variable in constructing a query to add the movieID and the submitted genre info (and rank 1) to tbl_MovieGenres • The $_POST['name'] for this matches the 2nd argument to dropbox_from_query() on your form page • Use the CSE 103 support function run_action_query() to run this query. http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103
Adding Movies Considerations • Q1: How can we determine if the “add” is successful? • Q2: How can we determine if a movie is in the database already? • Q3: What should we do if a movie is already in the database? http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103
A1: The IF statement • The IF statement lets us perform one or another set of actions based on the value of a test. • The test must have a value of either true or false. • It uses relational operators <, >,<>,==, etc. • If true, the first set of statements after the IF are executed. • If false, the statements after an else(following the if) are performed instead. http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103
Example: IF test if( $MovieID ==0) { print "No movie added"; } else { print "Movie added with ID = "; print $MovieID; } • Autonumber IDs are never 0, so if 0 was returned, we know we didn't get a "real" ID http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103
First Conditional Exercise • Modify your addmovie_handler.php page to test whether or not the action query on tbl_Movies is successful • What does it mean that a movie was added? • Display appropriate messages to the user and take other appropriate actions in each case. • What should you do if adding the record is successful? … if it is not successful? http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103
A2 & A3: Check for a pre-existing entry and action • Write an SQL query to test whether or not a MovieTitle and Year combination is already in the database. • What can we look for that we can easily test? • Use the returned value in an IF test • How should we test? What does our test mean if true? • If the movie IS NOT in the database, then add it as a new record and continue as before. • If the movie ISin the database, display a message to that effect plus its MovieID. • STOP and do not attempt to insert the data http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103
Dynamic Web Page Design • How should I put dynamic pages together to form a site? • Organization chart is very helpful, as used in CSE 101 • What information is needed to construct each page? • What interface do I want to present to the user? http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103
End-of-Term SIRS • Link on the Student Site Map • Three forms – Course, Lead , and Asst • Comments will be considered for future course development of CSE 101 • Available until Thursday, April 28th at 4pm, when UBTs are due • Necessary to access your BT Feedback http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103
UBT Databases • Each student in CSE 103 currently has a MySQL database • Database name is student’s msuNetID • Database is currently empty unless you already submitted an Access database for us to convert http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103
To create UBT Databases: • You submit (via e-mail) an Access db file to cse103@cse.msu.edu with desired table structures (fieldnames and datatypes) • Also look for other properties like Required? • Don't bother with lookups; we can't convert those • DO bother with relationships (helps us understand) • We will create the tables in your db from your Access sample. • You create the web forms and action pages to enter data into those tables and to manipulate the data as needed for your UBT project. http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103
A good UBT should: • Demonstrate good database design • Appropriate tables, fields, datatypes, keys, and relationships, as well as integrity and minimal redundancy (everything related to the 2.0 BT) • Demonstrate mastery of various queries • Both Select and Action, use of functions, calculated fields, aggregate functions, etc. • Demonstrate ability to learn new concepts • Use new functions, query types, etc. that we didn’t cover in-class or on any BT http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103
Remainder of Semester • Day 26 (Thurs/Mon) - In-Class BT Opportunity • Day 27 (next Tue/Wed) - In-Class Helproom • Day 28 (next Thurs/week from Mon) - In-Class BT Opportunity • Thursday, April 28th - UBTs due at 4 pm • On Days 26 and 28, your Lead will be in the CSE 103 office during class hours if you have already passed 3.0 and need UBT help • Feel free to e-mail with UBT questions when working http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103