Lab #7: Communicate with MySQL through PHP & HTML Forms

 

Purpose: In this lab, you should gain the basic skills to (i) manually create a simple web page by writing HTML tags into a .htm file using simple software like notepad or wordpad, (ii) use the HTML form tag in the web page to accept data submitted by the user and transmit the data to be processed by a PHP script, (iii) write a simple PHP script to process the data submitted and send feedbacks to the user, and (iv) upload both the web page and the PHP script to your CS X account to interact with them through the Internet.

 

Things to do and report: Go over steps below and inform me of your progress in these exercises in your weekly progress report.

 

Step 1: Play with a sample web page and a sample PHP script

 

 

Step 2: Create the sample tables under the test database of your own MySQL account

  • Log into your CS X server account. Then use the mysql client program to connect to the mysql server installed on the CS X server by entering the command: mysql u yourUserName p. After this, you will be prompted to enter your password to connect to the MySQL server installed on the CS X machine.
  • See this buildUpTestDB.txt script (open it and view the source under your browser). Build up the records of the salespeople, customers, and orders tables in the sample database by copying and pasting the commands in buildUpTestDB.txt into your mysql client window.
  • Comments: Alternatively you can either (ii) manually enter these commands, or (ii) you can use FileZilla to upload this file directly under the yourUserName ~ home folder of your CS X server and use the source command to run it under your mysql client window. (Although some people report some file access denial error when trying to source buildUpTestDB.txt in the second approach.), or (iii) as described in Lab #5 you can also use PHPmyAdmin to access your MySQL account and to run the buildUpTestDB.txt script.
  • If you cannot remember exactly how to accomplish the tasks described above, you may want to refresh your memory by looking at Lab #5 for the technical details.

 

 

Step 3: Enhance the web page as the interface to receive user inquiries into the Sample MySQL database tables

        Try to create a web page and a PHP script like what you see in Step 1 above. You should create a simple web page say, lab7Exp.htm, composed of HTML tags you learned from step 1 using simple software like notepad or wordpad. This page should contain at least two input fields of the text type and one submit button. People should be able to submit data to be processed by a lab7Exp.php script of your own. Your page should be able to display the contents of the salespeople table.

 

Step 4: Upload your version of the web page and the PHP script to the Sites folder of your CS X account.

  • Please upload the files you created in step 3 to the sites folder under your CS X server account, and play with it to make sure it works. You may want to refer to Lab#5 for the details of uploading and URL mapping.

 

Step 5: Access the web page through the Internet to interact with MySQL and retrieve data from the Sample database tables

  • Make sure everything works according to your planning. Send the URL of your web page (lab7Exp.htm) to me

 

Useful online references: