Presentation is loading. Please wait.

Presentation is loading. Please wait.

U:/msu/course/cse/103 Day 23, Slide 1 Review of Day 22 What query did you use to search for an actor by name? –Return matches.

Similar presentations


Presentation on theme: "U:/msu/course/cse/103 Day 23, Slide 1 Review of Day 22 What query did you use to search for an actor by name? –Return matches."— Presentation transcript:

1 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 23, Slide 1 Review of Day 22 What query did you use to search for an actor by name? –Return matches for first or last name –How many matches for ‘Fonda’? What name did you give the parameter for the actor name on the form? How did you construct the query in PHP to take the parameter from the form?

2 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 23, Slide 2 User Entry Form Construct a form to collect information about a movie not yet in the database Ask for the –Movie title –Year of release Should the use a get method or post? (we can set action later) Save the page as addmovie_form.php Remember, this page ONLY inputs data, it does not process it

3 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 23, Slide 3 Adding Movie Data What sort of query changes information in a database? Which type of query do we use to add a row to a table? How do we decide on the MovieID of a new movie?

4 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 23, Slide 4 Writing Data Create a handler page called addmovie_handler.php for the addmovie_form.php form page. Run an SQL query to add a movie’s row to the tbl_Movies table. –Use $_POST[‘Name’], where Name is the name= of an element on the form page –Use {curly braces} around the whole thing in a query $query = "… '{$_POST['Name']}', …" –Use insert_autonumbered_row($query) function to run the query. Note that this function also returns the new ID, in case you need it later. Display a “Record Added” message at bottom of page –If there are problems in queries, PHP will stop before then Test the form and target page together.

5 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 23, Slide 5 Update Movie Form The Movies database can store other sorts of data about movies too. Add a form element for entry of Genre data to the addmovie_form.php page –See next slide

6 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 23, Slide 6 Restricting Data Goal: to restrict user input to valid choices, e.g., lookup fields in Access Form elements can limit choices –List boxes, radio buttons, checkboxes, dropdown menus Make the Genre form element on the addmovie_form.php page a dropdown box. –The form page will now need to require() the cse103.php file if it has not already. –Use only Genres listed in tbl_Genres –Use print and the CSE 103 support function dropbox_from_query() Notice that PHP inside the form is perfectly OK!

7 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 23, Slide 7 Modify the form handler 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. Look at the documentation; see how they store an ID and print it out later. Instead of printing, use it in another query! –Use that variable in constructing a query to add the movie and genre info (assigned rank 1) to tbl_MovieGenres. –Use CSE 103 support function run_action_query() to run this query.

8 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 23, Slide 8 UBT Projects You should have your topic and have begun database design by now When your design is finished, e-mail access file as attachment to cse103@cse.msu.edu cse103@cse.msu.edu We will convert to MySQL and notify you –We will not import data. Create pages to add data –A small amount is sufficient, 5-10 rows or so Your new pages can use set_database() with the same host, user, and password as before. Your new database name = your MSUNetID. (Check documentation for more details.)

9 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 23, Slide 9 Day 24 Bridge Task INDIVIDUAL, not group work All students should come for a BT You will get the next BT you have not yet passed THREE opportunities left! (counting the one on Day 24) All are in-class opportunities; no need to sign up for makeups

10 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 23, Slide 10 Bridge Task 3.0 Covers all materials from Days 20 through 23 –Creating forms to handle data entry get vs. post tags and types tags and types –Creating php pages to act as handlers for these forms: Searches, adds Display query results (SELECTs), success messages (action) You will have your OWN copy of the MySQL Movies database to use on the BT, called movies_yourMSUNetID. You will need to edit your php pages to connect to that db rather than to the Movies db. (Check documentation.)

11 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 23, Slide 11 Bridge Task Students MUST have a picture ID for the BT on Day 24!


Download ppt "U:/msu/course/cse/103 Day 23, Slide 1 Review of Day 22 What query did you use to search for an actor by name? –Return matches."

Similar presentations


Ads by Google