http:www'cse'msu'educse103 - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

http:www'cse'msu'educse103

Description:

We will convert to MySQL and notify you. We will not import data. Create pages to add data ... set_database() with the same host, user, and password as before. ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 12
Provided by: vaughna3
Learn more at: https://www.msu.edu
Category:
Tags: cse | educse103 | hosting | http | msu | mysql | www

less

Transcript and Presenter's Notes

Title: http:www'cse'msu'educse103


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
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 ltformgt 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
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
Writing Data
  • Create a handler page called addmovie_handler.php
    for the addmovie_form.php form page.
  • Run an SQL query to add a movies row to the
    tbl_Movies table.
  • Use _POSTName, where Name is the name of an
    ltinputgt 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
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
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
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
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_at_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
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
Bridge Task 3.0
  • Covers all materials from Days 20 through 23
  • Creating forms to handle data entry
  • get vs. post
  • ltinputgt 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
Bridge Task
  • Students MUST have a picture ID for the BT on Day
    24!
Write a Comment
User Comments (0)
About PowerShow.com