Friday, March 13, 2009

Exercise 8: PHP and MySQL database access

1. Start with a simple table in the database:
mysql> SELECT * FROM employees;


Connect to database named test, and create table named employees:


Insert and select record in table employees:


2. Create a web page with the following PHP:

Web page display the first record in the employees table:


3. This is how we can add a record and is part of a file to create called add_record.html

The employees record add form:


4. The corresponding PHP file is add_record.php used with the POST method:

Record added into table employees by program add_record.php:
Correct typing error in INSERT statement from : "INERT" into "INSERT"


5. The last code example shows how to get multiple records:

Web page display multiple records:
Modified line 8: echo "", $myrow[2], ", ", $myrow[1], ""
To:
echo "", $myrow[0], ", ", $myrow[1], ""


No comments:

Post a Comment