Question
The object of this lab is to create a database connection to the vehicle_log.sql database you created and then create a simple interface to that
The object of this lab is to create a database connection to the vehicle_log.sql database you created and then create a simple interface to that database to show records.
Everything you need to complete this lab is in Chapter 4 of our textbook (Murachs PHP and MySQL 2nd Edition)
Log in to your virtual server as cpt283 with the password webapps
create a database (in your text editor) connection program similar to database.php in our textbook on page 141 that will connect to vehicle_log.sql
Name your file config.php
Include error handling in your database connection file (I have this already)
Create a php page named projectlab2.php
Include at the beginning of the projectlab2.php page a require statement like require ./config.php; to connect to the database
Referring to pages 130 to 135 in our textbook, query the database to SELECT all records in one table and then show the data found
You may have to manually insert some test data in your selected database table using phpMyAdmin to INSERT (tab) data records for testing
On page 135 you see example code of query that returns all the rows in a table and then uses a foreach statement embedded in HTML to create a HTML table displaying the data you ran the SELECT query on
Use page 135 as example replacing your table and field names in the proper places.
-----------------------------------------------------------------------------------------------------------------
config.php
getMessage(); include('database_error.php'); exit(); }
--------------------------------------------------------------------------------------------------------
Need projectlab2.php.......Edit the file below to match what is required.
prepare($queryCategory); $statement1->bindValue(':category_id', $category_id); $statement1->execute(); $category = $statement1->fetch(); $category_name = $category['categoryName']; $statement1->closeCursor(); // Get all categories $query = 'SELECT * FROM categories ORDER BY categoryID'; $statement = $db->prepare($query); $statement->execute(); $categories = $statement->fetchAll(); $statement->closeCursor(); // Get products for selected category $queryProducts = 'SELECT * FROM products WHERE categoryID = :category_id ORDER BY productID'; $statement3 = $db->prepare($queryProducts); $statement3->bindValue(':category_id', $category_id); $statement3->execute(); $products = $statement3->fetchAll(); $statement3->closeCursor(); ?>
Product Manager
Product List
Code | Name | Price | |
---|---|---|---|
Add Product
List Categories
Server: localhost Database: vehicle-log Table: vehicles Browse L Structure SQL Search 3c Insert k Export at Import / Operations Triggers Collation Attributes Null Default Extra Action Type int(12) varchar(100) latinl_swedish_ci varchar(100) latinl swedish ci int(4) int(4) varchar(50) latinl swedish ci varchar(30 atinl_swedish ci varchar(100) latin1_swedish_ci varchar(50) latinl swedish ci # Name hange. Drop> Primary u Unique Index More Change 8 Drop de Primary U Unique Index More eP Change Drop d> Primary LM Unique Index More Change Drop P Primary u UniqueIndex More Up Change Drop P Primary Lu Unique Index More Gp Change Drop d> Primary u Unique ,F] Index More op Change Drop P Primary LU Unique Index More Change 8 Drop Primary .U Unique gl Index More i? change e Drop P Primary Unique Index More Change 8 Drop de Primary U Unique Index More i? Change Drop P Primary Unique Index More 1 vehicle id 2 vehicle_type 3 vehiclemodel 4 vehicle-year No None AUTO INCREMENT C No None No None No None No None No None No None No None No None No None No None - 05 vehicle-year-purchased 6 vehiclecolor 7 vehicle VIN 8 vehicle_license tag 9 vehiclelicensestate - - - 10 vehicle_purchase price decimal(10,2) 11 vehicle_purchase_mileage decimal 10,1) nma Server: localhost Database: vehicle-log Table: vehicles Browse L Structure SQL Search 3c Insert k Export at Import / Operations Triggers Collation Attributes Null Default Extra Action Type int(12) varchar(100) latinl_swedish_ci varchar(100) latinl swedish ci int(4) int(4) varchar(50) latinl swedish ci varchar(30 atinl_swedish ci varchar(100) latin1_swedish_ci varchar(50) latinl swedish ci # Name hange. Drop> Primary u Unique Index More Change 8 Drop de Primary U Unique Index More eP Change Drop d> Primary LM Unique Index More Change Drop P Primary u UniqueIndex More Up Change Drop P Primary Lu Unique Index More Gp Change Drop d> Primary u Unique ,F] Index More op Change Drop P Primary LU Unique Index More Change 8 Drop Primary .U Unique gl Index More i? change e Drop P Primary Unique Index More Change 8 Drop de Primary U Unique Index More i? Change Drop P Primary Unique Index More 1 vehicle id 2 vehicle_type 3 vehiclemodel 4 vehicle-year No None AUTO INCREMENT C No None No None No None No None No None No None No None No None No None No None - 05 vehicle-year-purchased 6 vehiclecolor 7 vehicle VIN 8 vehicle_license tag 9 vehiclelicensestate - - - 10 vehicle_purchase price decimal(10,2) 11 vehicle_purchase_mileage decimal 10,1) nma
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started