CS222 Lab 12: MySQL, PHP, JavaScript


Instructor: Trish Cornez


This lab assumes the following MySQL relational database has been created and placed on the host server.
Please add at least 12 data records to this database.
To accurately test this table, enter 3 records containing the same first name.
For example: Bobo Smith, Bobo Greene, and Bobo Butler.



    Part A

    Use PHP with HTML to select a MySQL database and display the content.

    1. Construct the html page shown in the left image below. Use a form containing a submit button.
    2. Write a PHP script to perform the following tasks:
      • Connect to the MySQL database
      • Perform an SQL query to collect all records in the Friend database table
      • Print only the firstName, lastName, and email.







    Part B

    Allow PHP to receive input from HTML to selectively specify a MySQL database query.

    1. Modify the html page from Part A, as shown in the left image below.
      The page should now feature an input text box for the user to enter a first name.

    2. Modify the PHP script to allow the user to supply input that directs the database query.
      The SQL query should be able to SELECT all records with a matching firstName.






    Part C:

    JavaScript, PHP, and HTML5

    In this exercise, you will use JavaScript to collect data from the user and
    display the results of the SQL query within a DOM object. PHP will be used
    to connect to the database, build the SQL query and return the results.

    1. Write a JavaScript file to respond to the "Select" button, shown in the left figure below.
      A JavaScript method should collect input data and pass it to a PHP file in an XMLHttpRequest.

    2. The PHP file should be coded to peform the specified query and return the results formatted as an HTML table.




    Part D:

    JavaScript, PHP, and HTML5

    Using the same database from the previous exercises in this lab, write the necessary code to create the app below.






Practice 2

expenseADD.php





expenseApp.js





expenseApp.php