Assignment help PHP MySQL crash course - PowerPoint PPT Presentation

About This Presentation
Title:

Assignment help PHP MySQL crash course

Description:

Title: PowerPoint Presentation Last modified by: minzh812 Created Date: 1/1/1601 12:00:00 AM Document presentation format: On-screen Show (4:3) Other titles – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 10
Provided by: uuse
Category:

less

Transcript and Presenter's Notes

Title: Assignment help PHP MySQL crash course


1
Assignment help PHP MySQL crash course
  • Minpeng Zhu

2
Assignment
  • Implement a web application for movie management
    with a movie database as data storage and a web
    front-end using the Linux-Apache-MySQL-PHP (LAMP)
    web development framework
  • To be completed in groups (3-5)
  • Deploy solution
  • See TA in the lab to get a MySQL account for your
    group
  • Demo your solution during the scheduled labs or
    send solution (URL source) by email to TA by
    2012-02-03

3
Connecting to MySQL from PHP
  • lt?php
  • hostname "linne.it.uu.se"
  • username ""
  • password ""
  • connection mysql_connect(hostname, username,
    password)
  • or die("Could not open connection to
    database")
  • ?gt
  • Now the variable connection contains the
    information for your connection to MySQL. You can
    disconnect using
  • lt?php
  • mysql_close(connection)
  • or die("Could not close connection to
    database")
  • ?gt

4
Select a database, issue queries
  • Once you have connected successfully, you should
    select the database you will use. Then you can
    issue queries to the database.
  • lt?php
  • mysql_select_db("your DB name", connection)
  • or die("Could not select database")
  • result mysql_query("select from
    some_table") // No at the end
  • or die("Could not issue MySQL query")
  • ?gt
  • Now the variable result holds the query
    resultset.

5
Table of books
  • We have the following table of books, called
    books
  • How can we access this table from PHP?

book_name publish_year price rating
Rädd att flyga 1975 174 5
SCUM Manifesto 1968 189 5
6
Printing the results from a query
  • After issuing a query, you retrieve the results
    using
  • the variable result. Retrieve one row at a time
    using
  • mysql_fetch_assoc(result).
  • lt?php
  • result mysql_query("select book_name,
    publish_year from books")
  • if (mysql_num_rows(result) 0)
  • print("No results matching your queryltBRgt\n")
  • else
  • print("The Booksltbr /gt\n")
  • while (row mysql_fetch_assoc(result))
  • book_name row"book_name"
  • publish_year row"publish_year"
  • print("Book name book_name, Publish year
    publish_year\n")
  • ?gt

7
HTML forms and PHP variables
  • Create a HTML form
  • ltform action"add_book.php" method"POST"gt
  • ltinput type"text" name"book_name"gt
  • ltinput type"text" name"publish_year"gt
  • ltinput type"submit" value"Add Book"gt
  • lt/formgt
  • Then, in add_book.php, access the submitted
    values
  • lt?php
  • book_name _POST"book_name"
  • publish_year _POST"publish_year"
  • print("You entered book_name and
    publish_year")
  • ?gt

8
Drop down list
  • Given the following table of book categories,
    called category
  • Create drop down list
  • ltselect name"category"gt lt?php  result
    mysql_query("select id, name from
    category")  while(row mysql_fetch_assoc(resu
    lt))
  • id row"id"
  • name row"name" print("ltoption
    value'id'gtnamelt/optiongt\n")
    ?gtlt/selectgt
  • Selected value available in _POST"category"

id name
1 Sci-Fi
2 Poesi
9
Useful links
  • PHP - http//php.net/docs.php
  • MySQL using PHP - http//se.php.net/manual/en/book
    .mysql.php
  • NetBeans PHP IDE - http//netbeans.org/features/ph
    p/
  • PHPMySQL Tutorial - http//www.freewebmasterhelp.
    com/tutorials/phpmysql/
  • Website development - http//www.w3schools.com/
  • ApacheMySQLPHP on Windows (WAMP) -
    http//www.wampserver.com/en/
Write a Comment
User Comments (0)
About PowerShow.com