Uploaded by huyenvahoang

database report

advertisement
Vietnam National University
International University
DATABASE MANAGEMENT
SYSTEM PROJECT
CAR DATABASE
MANAGEMENT
Lê Minh Hoàng- MAMAIU19051
Phạm Phú Hanh-MAMAIU16010
Instructor: Trần Mạnh Hà
Requirement:
Car Manufacture Management (100 points). A simple car manufacture
management system manages multiple sets of data:
Car information contains identifier, title, type, year, color, manufacturer, options,
etc.
Manufacturer information contains identifier, name, nation, dealer, contact, etc.
Dealer information contains identifier, name, nation, address, contact, service,
etc.
Customer information contains identifier, name, address, car, year, dealer,
service, etc.
Several constraints need to be defined, at least cars belong to manufacturers,
manufacturers have dealers, customers possess cars and register dealers for
services, etc. This system allows managers to perform multiple functions on cars,
manufacturers, dealers and customers using the user interface.
I. ERD
Dealer
D_ID (PK)
Name
Nation
Address
Hotline
Email
Website
Top manager
Service
Manufacturer
Distribute
M_ID (PK)
Name
Nation
Address
Hotline
Email
Website
Top manager
Service
Produce
Customer
Car
CU_ID (PK)
Name
DOB
Nation
Address
Phone
Email
VIP_Level
Buying_date
Buying_quantity
C_ID (PK)
Name
Type
Year
Color
Seats
Price$
Status
Fuel
Manufacturer_date
Buy
II. DATABASE SCHEMA
Car
C_ID (PK)
M_ID (FK)
CU_ID (FK)
Carname
Type
Seats
Year
Price$
Color
Status
Type_of_fuel
Manufacturer_date
Dealer
Manufacturer
M_ID (PK)
Name
Nation
Address
Hotline
Email
Website
Top manager
Service
Customer
CU_ID (PK)
name
DOB
Nation
Address
Phone
Email
VIP_Level
Buying_date
Buying_quantity
Distribute
D_ID (PK; FK)
M_ID (PK; FK)
D_ID (PK)
Name
Nation
Address
Hotline
Email
Website
Top manager
Service
III. User interface and function on data.
A. Homepage interface
HTML code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Trang chủ</title>
<style>
body, html {
height: 100%;
margin: 0;
}
.bg {
/* The image used */
background-image: url("hinh-anh-o-to-con.jpg");
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size:cover;
}
</style>
</head>
<body>
<div class="bg">
<p style="color:rgba(0, 0, 255, 0.281);text-align:left;">
<a href="file:///C:/xampp/htdocs/Car%20interface.html"
style="color:white;">HOMEPAGE</a>
<h1 style="color: green; text-align: center;">
Car Manufacture Database Management
</h1>
<p style="color:blue;text-align: center;">
<a href="file:///C:/xampp/htdocs/show.html" style="color:blue;">SHOW
DATA</a>
</p>
<p style="color:blue; text-align: center;">
<a href="file:///C:/xampp/htdocs/select.html"
style="color:blue;">SELECT DATA</a>
</p>
<p style="color:blue; text-align: center;">
<a href="file:///C:/xampp/htdocs/update.html"
style="color:blue;">UPDATE DATA</a>
<p style="color:blue; text-align: center;">
<a href="file:///C:/xampp/htdocs/delete.html"
style="color:blue;">DELETE DATA</a>
<h2 style="color:white; margin-left: 30px ;">
Group 12
</h2>
<h2 style="color:white; margin-left: 10px ;">
Lê Minh Hoàng
</h2>
<h2 style="color:white; margin-left: 10px ;">
Phạm Phú Hanh
</h2>
</div>
</body>
</html>
So, with this user interface, users can now choose what to do with the data, first let see
what happen if they want to show data.
B. Show data
HTML code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
background-image: linear-gradient(to right,lightpink, red);
margin: 0;
padding: 0;
}
.content{
width: 100%;
height: auto;
background-color: gray;
padding: 10px;
}
.btn-home{
width: fit-content;
height: fit-content;
border-radius: 10px;
padding: 10px;
}
h1,h3, form,p{
text-align: center;
}
</style>
</head>
<body>
<a href="file:///C:/xampp/htdocs/Car%20interface.html" style="color:hsl(0,
0%, 100%);">HOMEPAGE</a>
<h2 style="text-align: center; color: aqua;">
LET'S FIND OUT INFORMATION
</h2>
<div class="content">
<div class="btn-home">
</div>
<h1>
<b>THE BEST CAR FOR YOU</b>
</h1>
<h3>
"Pleasure to serve you"
</h3>
<form action="http://localhost/show.php"< method="post"></method>
<form>
Show <select name="fname1">
<option value="customer">Customer</option>
<option value="dealer">Dealer</option>
<option value="manufacturer">Manufacturer</option>
<option value="car">Car</option>
<option value="distribute">Distribute</option>
</select>
</p>
<input type="submit" value="Submit" />
</form>
<p>
<img src="car2.jpg">
</p>
</div>
</body>
</html>
Then they can show which table they want to show using the select box
and submit button.
PHP code:
<?php
echo "
<style>
body{
background-image: linear-gradient(to right,white, lightpink);
margin: 0;
padding: 0;
}
.content{
width: 100%;
height: fit-content;
background-color: gray;
padding: 10px;
}
.btn-home{
width: fit-content;
height: fit-content;
border-radius: 10px;
padding: 10px;
}
h1,h3, form,p{
text-align: center;
}
table{
margin-left: auto;
margin-right: auto;
}
</style>";
// connect to server using your username and password
$con = mysqli_connect("localhost","car_manufacturer","begerdep");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$db_selected = mysqli_select_db($con, "car_manufacturer");
if (!$db_selected) {
echo "Failed to select DB. <br/>";
}
$fname1 = $_POST["fname1"];
echo"<h1 style='text-align: center; color:rgb(220,0,0);'>
YOUR RESULT IS
</h1>";
if($fname1 == "manufacturer"){
$sql = "select * from manufacturer";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to get data.<br/>";
}
//output in a table
echo "<table border='1'>
<tr>
<th>mid</th>
<th>name</th>
<th>nation</th>
<th>address</th>
<th>hotline</th>
<th>email</th>
<th>website</th>
<th>topmanager</th>
<th>service</th>
</tr>";
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td>" . $row["mid"] . "</td>";
echo "<td>" . $row["name"] . "</td>";
echo "<td>" . $row["nation"] . "</td>";
echo "<td>" . $row["address"] . "</td>";
echo "<td>" . $row["hotline"] . "</td>";
echo "<td>" . $row["email"] . "</td>";
echo "<td>" . $row["website"] . "</td>";
echo "<td>" . $row["topmanager"] . "</td>";
echo "<td>" . $row["service"] . "</td>";
echo "</tr>";
}
echo "</table>";
}
else if ($fname1 == "car") {
$sql = "select * from car";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to get data.<br/>";
}
//output in a table
echo "<table border='1'>
<tr>
<th>cid</th>
<th>mid</th>
<th>cuid</th>
<th>carname</th>
<th>type</th>
<th>seats</th>
<th>year</th>
<th>price$</th>
<th>color</th>
<th>status</th>
<th>type_of_fuel</th>
<th>manufacturer_date</th>
</tr>";
// MYSQLI_ASSOC for field name, MYSQLI_NUM for field index
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td>" . $row["cid"] . "</td>";
echo "<td>" . $row["mid"] . "</td>";
echo "<td>" . $row["cuid"] . "</td>";
echo "<td>" . $row["carname"] . "</td>";
echo "<td>" . $row["type"] . "</td>";
echo "<td>" . $row["seats"] . "</td>";
echo "<td>" . $row["year"] . "</td>";
echo "<td>" . $row["price$"] . "</td>";
echo "<td>" . $row["color"] . "</td>";
echo "<td>" . $row["status"] . "</td>";
echo "<td>" . $row["type_of_fuel"] . "</td>";
echo "<td>" . $row["manufacturer_date"] . "</td>";
echo "</tr>";
}
echo "</table>";
}
else if ($fname1 == "dealer"){
$sql = "select * from dealer";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to get data.<br/>";
}
//output in a table
echo "<table border='1'>
<tr>
<th>did</th>
<th>name</th>
<th>nation</th>
<th>address</th>
<th>hotline</th>
<th>email</th>
<th>website</th>
<th>topmanager</th>
<th>service</th>
</tr>";
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td>" . $row["did"] . "</td>";
echo "<td>" . $row["name"] . "</td>";
echo "<td>" . $row["nation"] . "</td>";
echo "<td>" . $row["address"] . "</td>";
echo "<td>" . $row["hotline"] . "</td>";
echo "<td>" . $row["email"] . "</td>";
echo "<td>" . $row["website"] . "</td>";
echo "<td>" . $row["topmanager"] . "</td>";
echo "<td>" . $row["service"] . "</td>";
echo "</tr>";
}
echo "</table>";
}
else if ($fname1 == "customer"){
$sql="select * from customer";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to get data.<br/>";
}
//output in a table
echo "<table border='1'>
<tr>
<th>cuid</th>
<th>name</th>
<th>DOB</th>
<th>nation</th>
<th>address</th>
<th>phone</th>
<th>email</th>
<th>VIP_Level</th>
<th>Buying_date</th>
<th>Buying_quantity</th>
</tr>";
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td>" . $row["cuid"] . "</td>";
echo "<td>" . $row["name"] . "</td>";
echo "<td>" . $row["DOB"] . "</td>";
echo "<td>" . $row["nation"] . "</td>";
echo "<td>" . $row["address"] . "</td>";
echo
echo
echo
echo
echo
echo
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"</tr>";
$row["phone"] . "</td>";
$row["email"] . "</td>";
$row["VIP_Level"] . "</td>";
$row["Buying_date"] . "</td>";
$row["Buying_quantity"] . "</td>";
}
echo "</table>";
}
else {
$sql = "select * from distribute";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to get data.<br/>";
}
//output in a table
echo "<table border='1'>
<tr>
<th>mid</th>
<th>did</th>
</tr>";
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td>" . $row["mid"] . "</td>";
echo "<td>" . $row["did"] . "</td>";
echo "</tr>";
}
echo "</table>";
}
echo "<p>
<img src='car3.jpg'>
</p>";
mysqli_free_result($result);
// close connection
mysqli_close($con);
First is the manufacturer data:
Second is the dealer data:
Third is the customer data:
Fourth is the car data:
And finally, the Distribute data:
This is the end of show function, next is the select data function.
C. Select data
HTML code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
background-image: linear-gradient(to right,lightpink, red);
margin: 0;
padding: 0;
}
.content{
width: 100%;
height: auto;
background-color: gray;
padding: 10px;
}
.btn-home{
width: fit-content;
height: fit-content;
border-radius: 10px;
padding: 10px;
}
h1,h3, form,p{
text-align: center;
}
</style>
</head>
<body>
<a href="file:///C:/xampp/htdocs/Car%20interface.html" style="color:hsl(0,
0%, 100%);">HOMEPAGE</a>
<h2 style="text-align: center; color: aqua;">
LET'S FIND OUT WHO BUY WHAT
</h2>
<div class="content">
<div class="btn-home">
</div>
<h1>
<b>THE BEST CAR FOR YOU</b>
</h1>
<h3>
"Pleasure to serve you"
</h3>
<form action="http://localhost/select.php"< method="post"></method>
<form>
Customer name= <input type='text' name='fname1'><br>
or
Car name= <input type='text' name='fname2'><br>
<input type="submit" value="Submit" />
</form>
<p>
<img src="car2.jpg">
</p>
</div>
</body>
</html>
PHP code:
<?php
echo "
<style>
body{
background-image: linear-gradient(to right,white, lightpink);
margin: 0;
padding: 0;
}
.content{
width: 100%;
height: fit-content;
background-color: gray;
padding: 10px;
}
.btn-home{
width: fit-content;
height: fit-content;
border-radius: 10px;
padding: 10px;
}
h1,h3, form,p{
text-align: center;
}
table{
margin-left: auto;
margin-right: auto;
}
</style>";
// connect to server using your username and password
$con = mysqli_connect("localhost","car_manufacturer","begerdep");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$db_selected = mysqli_select_db($con,"car_manufacturer");
if (!$db_selected) {
echo "Failed to select DB. <br/>";
}
$fname1 = $_POST["fname1"];
$fname2 = $_POST["fname2"];
echo"<h1 style='text-align: center; color:rgb(220,0,0);'>
YOUR RESULT IS
</h1>";
if($fname1 == null){
$sql = "select * from car, customer where car.cuid=customer.cuid and
car.carname like '%$fname2%'";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to get data.<br/>";
}
//output in a table
echo "<table border='1'>
<tr>
<th>cid</th>
<th>mid</th>
<th>cuid</th>
<th>carname</th>
<th>type</th>
<th>seats</th>
<th>year</th>
<th>price$</th>
<th>color</th>
<th>status</th>
<th>type_of_fuel</th>
<th>manufacturer_date</th>
<th>cuid</th>
<th>name</th>
<th>DOB</th>
<th>nation</th>
<th>address</th>
<th>phone</th>
<th>email</th>
<th>VIP_Level</th>
<th>Buying_date</th>
<th>Buying_quantity</th>
</tr>";
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td>" . $row["cid"] . "</td>";
echo "<td>" . $row["mid"] . "</td>";
echo "<td>" . $row["cuid"] . "</td>";
echo "<td>" . $row["carname"] . "</td>";
echo "<td>" . $row["type"] . "</td>";
echo "<td>" . $row["seats"] . "</td>";
echo "<td>" . $row["year"] . "</td>";
echo "<td>" . $row["price$"] . "</td>";
echo "<td>" . $row["color"] . "</td>";
echo "<td>" . $row["status"] . "</td>";
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"</tr>";
$row["type_of_fuel"] . "</td>";
$row["manufacturer_date"] . "</td>";
$row["cuid"] . "</td>";
$row["name"] . "</td>";
$row["DOB"] . "</td>";
$row["nation"] . "</td>";
$row["address"] . "</td>";
$row["phone"] . "</td>";
$row["email"] . "</td>";
$row["VIP_Level"] . "</td>";
$row["Buying_date"] . "</td>";
$row["Buying_quantity"] . "</td>";
}
echo "</table>";
}
else if($fname2 == null){
$sql = "select * from car, customer where car.cuid=customer.cuid and
customer.name like '%$fname1%'";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to get data.<br/>";
}
//output in a table
echo "<table border='1'>
<tr>
<th>cid</th>
<th>mid</th>
<th>cuid</th>
<th>carname</th>
<th>type</th>
<th>seats</th>
<th>year</th>
<th>price$</th>
<th>color</th>
<th>status</th>
<th>type_of_fuel</th>
<th>manufacturer_date</th>
<th>cuid</th>
<th>name</th>
<th>DOB</th>
<th>nation</th>
<th>address</th>
<th>phone</th>
<th>email</th>
<th>VIP_Level</th>
<th>Buying_date</th>
<th>Buying_quantity</th>
</tr>";
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td>" . $row["cid"] . "</td>";
echo "<td>" . $row["mid"] . "</td>";
echo "<td>" . $row["cuid"] . "</td>";
echo "<td>" . $row["carname"] . "</td>";
echo "<td>" . $row["type"] . "</td>";
echo "<td>" . $row["seats"] . "</td>";
echo "<td>" . $row["year"] . "</td>";
echo "<td>" . $row["price$"] . "</td>";
echo "<td>" . $row["color"] . "</td>";
echo "<td>" . $row["status"] . "</td>";
echo "<td>" . $row["type_of_fuel"] . "</td>";
echo "<td>" . $row["manufacturer_date"] . "</td>";
echo "<td>" . $row["cuid"] . "</td>";
echo "<td>" . $row["name"] . "</td>";
echo "<td>" . $row["DOB"] . "</td>";
echo "<td>" . $row["nation"] . "</td>";
echo "<td>" . $row["address"] . "</td>";
echo "<td>" . $row["phone"] . "</td>";
echo "<td>" . $row["email"] . "</td>";
echo "<td>" . $row["VIP_Level"] . "</td>";
echo "<td>" . $row["Buying_date"] . "</td>";
echo "<td>" . $row["Buying_quantity"] . "</td>";
echo "</tr>";
}
echo "</table>";
}
else
{
$sql = "(select * from car, customer where car.cuid=customer.cuid
and customer.name like '%$fname1%')
union (select * from car, customer where car.cuid=customer.cuid and
car.carname like '%$fname2%')";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to get data.<br/>";
}
//output in a table
echo "<table border='1'>
<tr>
<th>cid</th>
<th>mid</th>
<th>cuid</th>
<th>carname</th>
<th>type</th>
<th>seats</th>
<th>year</th>
<th>price$</th>
<th>color</th>
<th>status</th>
<th>type_of_fuel</th>
<th>manufacturer_date</th>
<th>cuid</th>
<th>name</th>
<th>DOB</th>
<th>nation</th>
<th>address</th>
<th>phone</th>
<th>email</th>
<th>VIP_Level</th>
<th>Buying_date</th>
<th>Buying_quantity</th>
</tr>";
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td>" . $row["cid"] . "</td>";
echo "<td>" . $row["mid"] . "</td>";
echo "<td>" . $row["cuid"] . "</td>";
echo "<td>" . $row["carname"] . "</td>";
echo "<td>" . $row["type"] . "</td>";
echo "<td>" . $row["seats"] . "</td>";
echo "<td>" . $row["year"] . "</td>";
echo "<td>" . $row["price$"] . "</td>";
echo "<td>" . $row["color"] . "</td>";
echo "<td>" . $row["status"] . "</td>";
echo "<td>" . $row["type_of_fuel"] . "</td>";
echo "<td>" . $row["manufacturer_date"] . "</td>";
echo "<td>" . $row["cuid"] . "</td>";
echo "<td>" . $row["name"] . "</td>";
echo "<td>" . $row["DOB"] . "</td>";
echo "<td>" . $row["nation"] . "</td>";
echo "<td>" . $row["address"] . "</td>";
echo
echo
echo
echo
echo
echo
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"</tr>";
$row["phone"] . "</td>";
$row["email"] . "</td>";
$row["VIP_Level"] . "</td>";
$row["Buying_date"] . "</td>";
$row["Buying_quantity"] . "</td>";
}
echo "</table>";
}
echo "<p>
<img src='car3.jpg'>
</p>";
mysqli_free_result($result);
// close connection
mysqli_close($con);
In this interface, the user can select the information “who buy what car” by using the 2
type boxes and the result will be the join of 2 tables, customer and car:
For example:
-Find customer whose name like ‘mi’.
Find car whose name like ‘hy’
Find customer whose name like ‘ur’ or car name like ‘x4’
This is the end of this section. Next we will see if the user chooses to update data
D. Update data
In this section, we divide the function into add and change data.
HTML for add data, for simplicity, we will demonstrate only when the user wants to add
new car data:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
background-image: linear-gradient(to right,lightpink, red);
margin: 0;
padding: 0;
}
.content{
width: 100%;
height: fit-content;
background-color: gray;
padding: 10px;
}
.btn-home{
width: fit-content;
height: fit-content;
border-radius: 10px;
padding: 10px;
}
h1,h3, form,p{
text-align: center;
}
table{
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<a href="file:///C:/xampp/htdocs/Car%20interface.html" style="color:hsl(0,
0%, 100%);">HOMEPAGE</a>
<h2 style="text-align: center; color: aqua;">
LET'S ADD NEW CAR INFORMATION
</h2>
<div class="content">
<h1>
<b>THE BEST CAR FOR YOU</b>
</h1>
<h3>
"Pleasure to serve you"
</h3>
<form action="http://localhost/addcar.php"< method="post"></method>
<form>
<table>
<tr>
<td>C_ID</td>
<td><input type='text' name='fname1'><br></td>
</tr>
<tr>
<td>M_ID</td>
<td><input type='text' name='fname2'><br></td>
</tr>
<tr>
<td>CU_ID</td>
<td><input type='text' name='fname3'><br></td>
</tr>
<tr>
<td>Carname</td>
<td><input type='text' name='fname4'><br></td>
</tr>
<tr>
<td>Type</td>
<td><input type='text' name='fname5'><br></td>
</tr>
<tr>
<td>Seats</td>
<td><input type='text' name='fname6'><br></td>
</tr>
<tr>
<td>Year</td>
<td><input type='text' name='fname7'><br></td>
</tr>
<tr>
<td>Price$</td>
<td><input type='text' name='fname8'><br></td>
</tr>
<tr>
<td>Color</td>
<td><input type='text' name='fname9'><br></td>
</tr>
<tr>
<td>Status</td>
<td><input type='text' name='fname10'><br></td>
</tr>
<tr>
<td>Type_of_fuel</td>
<td><input type='text' name='fname11'><br></td>
</tr>
<tr>
<td>Manufacture_date</td>
<td><input type='text' name='fname12'><br></td>
</tr>
</table>
<p>
<input type="submit" value="Submit" />
</p>
</form>
<p>
<img src="car2.jpg">
</p>
</div>
</body>
</html>
The user now can add new data into the database.
For example:
C_ID= ‘44444’
M_ID=’10004’
CU_ID=’30013’
Carname=’BMW mui tran’
Type=’Convertible’
Seats=’9’
Price$=’888888’
Year=’2020’
Color=’Beige’
Status=’Really new’
Type_of_fuel=’Water’
Manufacture_date=’2020/1/1’
As you can see, the new information is added into the car table.
Next, let see what happens if the user wants to change data in the table.
HTML code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
background-image: linear-gradient(to right,lightpink, red);
margin: 0;
padding: 0;
}
.content{
width: 100%;
height: auto;
background-color: gray;
padding: 10px;
}
.btn-home{
width: fit-content;
height: fit-content;
border-radius: 10px;
padding: 10px;
}
h1,h3, form,p{
text-align: center;
}
</style>
</head>
<body>
<a href="file:///C:/xampp/htdocs/Car%20interface.html" style="color:hsl(0,
0%, 100%);">HOMEPAGE</a>
<h2 style="text-align: center; color: aqua;">
LET'S CHANGE INFORMATION
</h2>
<div class="content">
<div class="btn-home">
</div>
<h1>
<b>THE BEST CAR FOR YOU</b>
</h1>
<h3>
"Pleasure to serve you"
</h3>
<form action="http://localhost/change.php"< method="post"></method>
<form>
Change <select name="fname1">
<option value="customer">Customer</option>
<option value="dealer">Dealer</option>
<option value="manufacturer">Manufacturer</option>
<option value="car">Car</option>
</select>
</p>
Where ID= <input type='text' name='fname2'><br>
</p>
Attribute= <select name="fname3">
<option
<option
<option
<option
<option
<option
<option
<option
<option
<option
<option
<option
<option
<option
<option
<option
<option
<option
<option
<option
<option
<option
value="name">name</option>
value="nation">nation</option>
value="address">address</option>
value="hotline">hotline</option>
value="phone">phone</option>
value="email">email</option>
value="website">website</option>
value="topmanager">topmanager</option>
value="service">service</option>
value="carname">carname</option>
value="type">type</option>
value="year">year</option>
value="color">color</option>
value="seats">seats</option>
value="fuel">fuel</option>
value="price$">price$</option>
value="status">status</option>
value="manufacturer_date">manufacturer_date</option>
value="DOB">DOB</option>
value="VIP_Level">VIP_Level</option>
value="buying_date">buying_date</option>
value="buying_quantity">buying_quantity</option>
</p>
</select>
</p>
Into= <input type='text' name='fname4'><br>
</p>
<input type="submit" value="Submit" />
</form>
<p>
<img src="car2.jpg">
</p>
</div>
</body>
</html>
PHP code:
<?php
echo "
<style>
body{
background-image: linear-gradient(to right,white, lightpink);
margin: 0;
padding: 0;
}
.content{
width: 100%;
height: fit-content;
background-color: gray;
padding: 10px;
}
.btn-home{
width: fit-content;
height: fit-content;
border-radius: 10px;
padding: 10px;
}
h1,h3, form,p{
text-align: center;
}
table{
margin-left: auto;
margin-right: auto;
}
</style>";
// connect to server using your username and password
$con = mysqli_connect("localhost","car_manufacturer","begerdep");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$db_selected = mysqli_select_db($con,"car_manufacturer");
if (!$db_selected) {
echo "Failed to select DB. <br/>";
}
$fname1 = $_POST["fname1"];
$fname2 = $_POST["fname2"];
$fname3 = $_POST["fname3"];
$fname4 = $_POST["fname4"];
echo"<h1 style='text-align: center; color:rgb(220,0,0);'>
YOUR RESULT IS
</h1>";
if($fname1 == 'customer'){
$sql = "update customer set $fname3 = '$fname4' where cuid = $fname2";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to change data.<br/>";
}
$sql = "select * from customer where cuid=$fname2";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to get data.<br/>";
}
//output in a table
echo "<table border='1'>
<tr>
<th>cuid</th>
<th>name</th>
<th>DOB</th>
<th>nation</th>
<th>address</th>
<th>phone</th>
<th>email</th>
<th>VIP_Level</th>
<th>Buying_date</th>
<th>Buying_quantity</th>
</tr>";
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td>" . $row["cuid"] . "</td>";
echo "<td>" . $row["name"] . "</td>";
echo "<td>" . $row["DOB"] . "</td>";
echo "<td>" . $row["nation"] . "</td>";
echo "<td>" . $row["address"] . "</td>";
echo "<td>" . $row["phone"] . "</td>";
echo "<td>" . $row["email"] . "</td>";
echo "<td>" . $row["VIP_Level"] . "</td>";
echo "<td>" . $row["Buying_date"] . "</td>";
echo "<td>" . $row["Buying_quantity"] . "</td>";
echo "</tr>";
}
echo "</table>";
}
else if($fname1 == 'dealer'){
$sql = "update dealer set $fname3 = '$fname4' where did = $fname2";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to change data.<br/>";
}
$sql = "select * from dealer where did=$fname2";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to get data.<br/>";
}
echo "<table border='1'>
<tr>
<th>did</th>
<th>name</th>
<th>nation</th>
<th>address</th>
<th>hotline</th>
<th>email</th>
<th>website</th>
<th>topmanager</th>
<th>service</th>
</tr>";
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
"<tr>";
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"</tr>";
$row["did"] . "</td>";
$row["name"] . "</td>";
$row["nation"] . "</td>";
$row["address"] . "</td>";
$row["hotline"] . "</td>";
$row["email"] . "</td>";
$row["website"] . "</td>";
$row["topmanager"] . "</td>";
$row["service"] . "</td>";
}
echo "</table>";
}
else if($fname1 == 'manufacturer'){
$sql = "update manufacturer set $fname3 = '$fname4' where mid =
$fname2";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to change data.<br/>";
}
$sql = "select * from manufacturer where mid=$fname2";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to get data.<br/>";
}
echo "<table border='1'>
<tr>
<th>mid</th>
<th>name</th>
<th>nation</th>
<th>address</th>
<th>hotline</th>
<th>email</th>
<th>website</th>
<th>topmanager</th>
<th>service</th>
</tr>";
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td>" . $row["mid"] . "</td>";
echo "<td>" . $row["name"] . "</td>";
echo "<td>" . $row["nation"] . "</td>";
echo "<td>" . $row["address"] . "</td>";
echo "<td>" . $row["hotline"] . "</td>";
echo
echo
echo
echo
echo
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"</tr>";
$row["email"] . "</td>";
$row["website"] . "</td>";
$row["topmanager"] . "</td>";
$row["service"] . "</td>";
}
echo "</table>";
}
else if($fname1 == 'car')
{
$sql = "update car set $fname3 = '$fname4' where cid = $fname2";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to change data.<br/>";
}
$sql = "select * from car where cid=$fname2";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to get data.<br/>";
}
echo "<table border='1'>
<tr>
<th>cid</th>
<th>mid</th>
<th>cuid</th>
<th>carname</th>
<th>type</th>
<th>seats</th>
<th>year</th>
<th>price$</th>
<th>color</th>
<th>status</th>
<th>type_of_fuel</th>
<th>manufacturer_date</th>
</tr>";
// MYSQLI_ASSOC for field name, MYSQLI_NUM for field index
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td>" . $row["cid"] . "</td>";
echo "<td>" . $row["mid"] . "</td>";
echo "<td>" . $row["cuid"] . "</td>";
echo "<td>" . $row["carname"] . "</td>";
echo "<td>" . $row["type"] . "</td>";
echo "<td>" . $row["seats"] . "</td>";
echo "<td>" . $row["year"] . "</td>";
echo "<td>" . $row["price$"] . "</td>";
echo
echo
echo
echo
echo
"<td>" .
"<td>" .
"<td>" .
"<td>" .
"</tr>";
$row["color"] . "</td>";
$row["status"] . "</td>";
$row["type_of_fuel"] . "</td>";
$row["manufacturer_date"] . "</td>";
}
echo "</table>";
}
echo "<p>
<img src='car3.jpg'>
</p>";
mysqli_free_result($result);
// close connection
mysqli_close($con);
The first selection box is where the user can choose the table, the type box bellow is for
the user to input ID of the column they want to change, in the attribute selection box,
there are all of the attribute in four main tables, and they can change that information
into new want by using the final type box.
For example:
Let change the price of the car into 1234567 where id=40002
Let change the customer’s VIP_Level into ‘normal’ where id=30012
Let change the manufacturer service into ‘domestic’ where id=10006
Finally, let change dealer’s top manager into ‘Tran Thanh’ where id=20001
That is the end of update data section. Finally, we come to the delete function.
E. Delete data
HTML code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
background-image: linear-gradient(to right,lightpink, red);
margin: 0;
padding: 0;
}
.content{
width: 100%;
height: auto;
background-color: gray;
padding: 10px;
}
.btn-home{
width: fit-content;
height: fit-content;
border-radius: 10px;
padding: 10px;
}
h1,h3, form,p{
text-align: center;
}
</style>
</head>
<body>
<a href="file:///C:/xampp/htdocs/Car%20interface.html" style="color:hsl(0,
0%, 100%);">HOMEPAGE</a>
<h2 style="text-align: center; color: aqua;">
LET'S DELETE INFORMATION
</h2>
<div class="content">
<div class="btn-home">
</div>
<h1>
<b>THE BEST CAR FOR YOU</b>
</h1>
<h3>
"Pleasure to serve you"
</h3>
<form action="http://localhost/delete.php"< method="post"></method>
<form>
Delete <select name="fname1">
<option value="customer">Customer</option>
<option value="dealer">Dealer</option>
<option value="manufacturer">Manufacturer</option>
<option value="car">Car</option>
</select>
</p>
Where ID= <input type='text' name='fname2'><br>
</p>
<input type="submit" value="Submit" />
</p>
</form>
<p>
<img src="car2.jpg">
</p>
</div>
</body>
</html>
PHP code:
<?php
echo "
<style>
body{
background-image: linear-gradient(to right,white, lightpink);
margin: 0;
padding: 0;
}
.content{
width: 100%;
height: fit-content;
background-color: gray;
padding: 10px;
}
.btn-home{
width: fit-content;
height: fit-content;
border-radius: 10px;
padding: 10px;
}
h1,h3, form,p{
text-align: center;
}
table{
margin-left: auto;
margin-right: auto;
}
</style>";
// connect to server using your username and password
$con = mysqli_connect("localhost","car_manufacturer","begerdep");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$db_selected = mysqli_select_db($con, "car_manufacturer");
if (!$db_selected) {
echo "Failed to select DB. <br/>";
}
$fname1 = $_POST["fname1"];
$fname2 = $_POST["fname2"];
echo"<h1 style='text-align: center; color:rgb(220,0,0);'>
YOUR RESULT IS
</h1>";
if ($fname1 == "car") {
$sql = "DELETE FROM car WHERE cid = $fname2;" ;
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to DELETE data.<br/>";
}
$sql = "select * from car";
if (!($result = mysqli_query($con,$sql))) {
echo "Failed to get data.<br/>";
}
//output in a table
echo "<table border='1'>
<tr>
<th>cid</th>
<th>mid</th>
<th>cuid</th>
<th>carname</th>
<th>type</th>
<th>seats</th>
<th>year</th>
<th>price$</th>
<th>color</th>
<th>status</th>
<th>type_of_fuel</th>
<th>manufacturer_date</th>
</tr>";
// MYSQLI_ASSOC for field name, MYSQLI_NUM for field index
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td>" . $row["cid"] . "</td>";
echo "<td>" . $row["mid"] . "</td>";
echo "<td>" . $row["cuid"] . "</td>";
echo "<td>" . $row["carname"] . "</td>";
echo "<td>" . $row["type"] . "</td>";
echo "<td>" . $row["seats"] . "</td>";
echo "<td>" . $row["year"] . "</td>";
echo "<td>" . $row["price$"] . "</td>";
echo "<td>" . $row["color"] . "</td>";
echo "<td>" . $row["status"] . "</td>";
echo "<td>" . $row["type_of_fuel"] . "</td>";
echo "<td>" . $row["manufacturer_date"] . "</td>";
echo "</tr>";
}
echo "</table>";
}
echo "<p>
<img src='car3.jpg'>
</p>";
mysqli_free_result($result);
// close connection
mysqli_close($con);
Using this interface, user can delete entire column with the ID in the type box. Because
of the constraint of foreign key, we demonstrate only the car table.
For example:
Let delete car table where id= 40003
IV. Task breakdown.
Come up with ideas and design ERD, Database Design: Hoàng, Hanh
Insert table in SQL: Hanh
HTML coding: Hoàng
PHP coding:
+ Hoàng: Show, Select
+ Hanh: Delete, Add, Change
Report making: Hoàng.
~~THE END ~~
Download