Database case study
Do EITHER Case A or Case B as your database case study for this exercise.
On your own machine, setup and testeither database system and report your findings.
I will use Case B as my database case study for this exercise.
Case B: PHP and MySQL
Some server practice with PHP
Instead of using individual versions of PHP, MySQL, phpMyAdmin and Apache, I'm using the XAMPP 1.7.3 for window which is a setup packing for PHP 5.3.1, MySQL 5.1.41, Apache 2.2.14 and phpMyAdmin 3.2.4. The installation process is very simply and it only takes about 5 minutes to finish. This XAMPP is a lite and green version which it will not install any services in the windows environment.
After installation, the Apache is not working due to the Skype install in my computer is using the port 443. I need to close the Skype application in order to turn on the Apache service.
2. Create a web application , hello_world.php
The result is as follow
3. Create an HTML page with teh form:
4. Then, Create a PHP file named submit.php with the following code:
The coding has been modified from $myname into $_GET[myname] in order to work.
The result for 3 and 4 is as follow:
After press RETURN, the result is as follow:
5.
a. Create a web page, the corresponding code is as follow:
The result is as follow:
Because the mydatabase is empty, I need to use the phpMyAdmin tool to input the employee data into the employees table in order to give the output.
b. Create the add_record.html
c. Create the corresponding add_record.php with the POST method:
The original code provided by the study guide is not written for the windows environment. I need to change the $first,$last,$address,$position into $_POST[first], $_POST[last], $_POST[address],$_POST[position],
in order to make the program to run. Moreover, there is also a typo mistake in the original coding, the INERT needs to correct into INSERT.
The execution result is as follow:
After putting in the required data and press the Enter, the result is as follow:
d. Get multiple records from the database
The correct coding is as below:
The original coding in the study guide is not grabbing the correct data from the employees database. The first, last, address and position is count from 0 to 3 rather than 1-4. Therefore the $myrow[2] and $myrow[1] needs to change to $myrow[1] and $myrow[0] correspondingly.
The result is as follow:
Task completed.
Conclusion
This is a very good exercise to understand the PHP and database relationship. But it is very time consuming for setup and moreover a lot of steps is not cover in the study guide. I had used almost 10 hours to finish this exercise. Fortunately, by follow the blog from Leo Lee and read some hints from the internet (w3schools,2010), I can finally finish the task.
No comments:
Post a Comment