0% found this document useful (0 votes)
32 views12 pages

Practical 7.2

The document outlines a practical assignment to create a website using JSON to insert data into a PHP server database. It includes HTML code for a catering website featuring sections like About, Menu, and Contact, along with PHP code snippets for inserting product details into a MySQL database. Each product has corresponding JSON data for its name and price, which is processed and stored in the database.

Uploaded by

Faisal Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views12 pages

Practical 7.2

The document outlines a practical assignment to create a website using JSON to insert data into a PHP server database. It includes HTML code for a catering website featuring sections like About, Menu, and Contact, along with PHP code snippets for inserting product details into a MySQL database. Each product has corresponding JSON data for its name and price, which is processed and stored in the database.

Uploaded by

Faisal Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Subject: Applications of AWT Id: 21102047

Practical 7
Aim 7.2: Create a website using JSON to insert data in the PHP Server Database.

CODE:

1. HTML Code

<html>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<style>

body {font-family:"Times New Roman", serif}

h1,h2,h3,h4,h5,h6 {font-family:serif; letter-spacing:5px}

* {
box-sizing: border-box;
}

.column {
float: left;
width: 25%;
padding: 3px;
}

/* Clearfix (clear floats) */


.row::after {
content: "";
clear: both;
display: table;
}
</style>
<body>

<!-- Navigation (Sits on top) -->


<div class="w3-top w3-bar w3-white w3-padding w3-card w3-wide">
<a href="#home" class="w3-bar-item w3-button">Sinfully Sweet !!!!</a>

<!-- Right-sided navbar links. Hide them on small screens -->


<div class="w3-right w3-hide-small">
<a href="#about" class="w3-bar-item w3-button">About</a>
<a href="#menu" class="w3-bar-item w3-button">Menu</a>
<a href="#contact" class="w3-bar-item w3-button">Contact</a>
</div>
</div>
<div class="container">
<img src="C:\xxampp\htdocs\AWT\7.2\img1.jpg" style="width:100%; height:
740;">
Subject: Applications of AWT Id: 21102047

<div class="centered"></div>
</div>
<hr>
<!-- About Section -->
<div class="w3-row w3-padding-64" id="about">
<div class="w3-col m6 w3-padding-large ">
<img src="C:\xxampp\htdocs\AWT\7.2\img2.jpg" width="650" height="700">
</div>

<h1 class="w3-center">About Catering</h1><br>


<div class="w3-col m6 w3-padding-large">
<h5 class="w3-center">Tradition since 1889</h5>
<p class="w3-large">The Catering was founded in blabla by Mr. Smith in
lorem ipsum dolor sit amet, consectetur adipiscing elit consectetur
adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
iruredolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur.We only use <span class="w3-tag w3-light-
grey">seasonal</span> ingredients.</p>
<p class="w3-large w3-text-grey w3-hide-medium">Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim
id est laborum consectetur adipiscing elit, sed do eiusmod
temporincididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.</p>
</div>
</div>
<hr>

<!-- Menu Section -->


<h1 class="w3-center">Our Menu</h1><br>
<div class="row">
<div class="column">
<img src="C:\xxampp\htdocs\AWT\7.2\img5.jpg" width="300"
height="350"><br><h3 style="color:rgb(9, 12, 77);">Cookies - Rs.
300</h3>
<h4 style="font-family:courier;" class="card-title">Yummy
cookies!!</h4>
<a href="ww1.php" class="btn btn-primary">BUY NOW</a>
</div>

<div class="column">
<img src="C:\xxampp\htdocs\AWT\7.2\img4.jpg" width="300"
height="350"><br><h3 style="color:rgb(9, 12, 77);">Muffins - Rs.
250</h3>
<h4 style="font-family:courier;" class="card-title">Delicious Muffins!!
</h4>
Subject: Applications of AWT Id: 21102047

<a href="w2.php" class="btn btn-primary">BUY NOW</a>


</div>

<div class="column">
<img src="C:\xxampp\htdocs\AWT\7.2\img6.jpeg" width="300"
height="350"><br><h3 style="color:rgb(9, 12, 77);">Macarons - Rs.
350</h3>
<h4 style="font-family:courier;" class="card-title">Cute
Macarons!!</h4>
<a href="w3.php" class="btn btn-primary">BUY NOW</a>
</div>

<div class="column">
<img src="C:\xxampp\htdocs\AWT\7.2\img7.jpeg" width="300"
height="350"><br><h3 style="color:rgb(9, 12, 77);">Waffles - Rs.
150</h3>
<h4 style="font-family:courier;" class="card-title">Sweetest Waffles!!
</h4>
<a href="w4.php" class="btn btn-primary">BUY NOW</a>
</div>

<div class="column">
<img src="C:\xxampp\htdocs\AWT\7.2\img8.jpeg" width="300"
height="350"><br><h3 style="color:rgb(9, 12, 77);">Cheesecake - Rs.
200</h3>
<h4 style="font-family:courier;" class="card-title">Cheesy
Cheesecakes!!</h4>
<a href="w5.php" class="btn btn-primary">BUY NOW</a>
</div>

<div class="column">
<img src="C:\xxampp\htdocs\AWT\7.2\img9.jpg" width="300"
height="350"><br><h3 style="color:rgb(9, 12, 77);">Treats - Rs.
300</h3>
<h4 style="font-family:courier;" class="card-title">Mini Treats!!</h4>
<a href="w6.php" class="btn btn-primary">BUY NOW</a>
</div>

<div class="column">
<img src="C:\xxampp\htdocs\AWT\7.2\img10.jpg" width="300"
height="350"><br><h3 style="color:rgb(9, 12, 77);">Doughnuts - Rs.
250</h3>
<h4 style="font-family:courier;" class="card-title">Tiny
Doughnuts!!</h4>
<a href="w7.php" class="btn btn-primary">BUY NOW</a>
</div>

<div class="column">
Subject: Applications of AWT Id: 21102047

<img
src="https://i.pinimg.com/originals/33/1c/9e/331c9e2839c86dd171b6f134a4
be1903.jpg" width="300" height="350"><br><h3 style="color:rgb(9, 12,
77);">Candies - Rs. 150</h3>
<h4 style="font-family:courier;" class="card-title">Colorful Candies!!
</h4>
<a href="w8.php" class="btn btn-primary">BUY NOW</a>
</div>
<br>
<!-- Contact Section -->
<div class="w3-container w3-padding-64" id="contact">
<h1>Contact</h1><br>
<p>We offer full-service catering for any event, large or small. We
understand your needs and we will cater the food to satisfy the
biggerst criteria of them all, both look and taste. Do not hesitate to
contact us.</p>
<p class="w3-text-blue-grey w3-large"><b>Catering Service,
Vadodara</b></p>
<p>You can also contact us by phone 6359206814 or email
catering@catering.com, or you can send us a message here:</p>
<form action="/action_page.php" target="_blank">
<p><input class="w3-input w3-padding-16" type="text"
placeholder="Name" required name="Name"></p>
<p><input class="w3-input w3-padding-16" type="number"
placeholder="How many people" required name="People"></p>
<p><input class="w3-input w3-padding-16" type="datetime-local"
placeholder="Date and time" required name="date" value="2020-11-
16T20:00"></p>
<p><input class="w3-input w3-padding-16" type="text"
placeholder="Message \ Special requirements" required
name="Message"></p>
<p><button class="w3-button w3-light-grey w3-section"
type="submit">SEND MESSAGE</button></p>
</form>
</div>
</body>
</html>

2. PHP Code
a) Code for Image 1(Cookies):

<?php
$con =mysqli_connect("localhost", "root", "","awt");
$json_obj = '{
"product": "Cookies",
"price":"300"
}';
Subject: Applications of AWT Id: 21102047

//convert to stdclass object


$c_data = json_decode($json_obj);

//store the element values into variables


$product = $c_data->product;
$price = $c_data->price;

//insert values into mysql database


$sql="INSERT INTO orders(product,price) VALUES ('$product', '$price')";

if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$retval = mysqli_query( $con, $sql );

if(! $retval ) {
die('Could not enter data: ' . mysqli_error($con));
}
echo "Entered data successfully\n";
mysqli_close($con);
echo "<a href=1.html>Back</a>";
?>

b) Code for Image 2(Muffins):

<?php
$con =mysqli_connect("localhost", "root", "","awt");
$json_obj = '{
"product": "Muffins",
"price":"250"
}';

//convert to stdclass object


$c_data = json_decode($json_obj);

//store the element values into variables


$product = $c_data->product;
$price = $c_data->price;

//insert values into mysql database


$sql="INSERT INTO orders(product,price) VALUES ('$product', '$price')";

if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$retval = mysqli_query( $con, $sql );
Subject: Applications of AWT Id: 21102047

if(! $retval ) {
die('Could not enter data: ' . mysqli_error($con));
}
echo "Entered data successfully\n";
mysqli_close($con);
echo "<a href=1.html>Back</a>";
?>

c) Code for Image 3(Macarons):

<?php
$con =mysqli_connect("localhost", "root", "","awt");
$json_obj = '{
"product": "Macarons",
"price":"350"
}';

//convert to stdclass object


$c_data = json_decode($json_obj);

//store the element values into variables


$product = $c_data->product;
$price = $c_data->price;

//insert values into mysql database


$sql="INSERT INTO orders(product,price) VALUES ('$product', '$price')";

if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$retval = mysqli_query( $con, $sql );

if(! $retval ) {
die('Could not enter data: ' . mysqli_error($con));
}
echo "Entered data successfully\n";
mysqli_close($con);
echo "<a href=1.html>Back</a>";
?>

d) Code for Image 4(Waffles):

<?php
$con =mysqli_connect("localhost", "root", "","awt");
$json_obj = '{
"product": "Waffles",
Subject: Applications of AWT Id: 21102047

"price":"150"
}';

//convert to stdclass object


$c_data = json_decode($json_obj);

//store the element values into variables


$product = $c_data->product;
$price = $c_data->price;

//insert values into mysql database


$sql="INSERT INTO orders(product,price) VALUES ('$product', '$price')";

if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$retval = mysqli_query( $con, $sql );

if(! $retval ) {
die('Could not enter data: ' . mysqli_error($con));
}
echo "Entered data successfully\n";
mysqli_close($con);
echo "<a href=1.html>Back</a>";
?>

e) Code for Image 5(Cheesecake):

<?php
$con =mysqli_connect("localhost", "root", "","awt");
$json_obj = '{
"product": "Cheese Cake",
"price":"200"
}';

//convert to stdclass object


$c_data = json_decode($json_obj);

//store the element values into variables


$product = $c_data->product;
$price = $c_data->price;

//insert values into mysql database


$sql="INSERT INTO orders(product,price) VALUES ('$product', '$price')";

if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
Subject: Applications of AWT Id: 21102047

exit();
}
$retval = mysqli_query( $con, $sql );

if(! $retval ) {
die('Could not enter data: ' . mysqli_error($con));
}
echo "Entered data successfully\n";
mysqli_close($con);
echo "<a href=1.html>Back</a>";
?>

f) Code for Image 6(Treats):

<?php
$con =mysqli_connect("localhost", "root", "","awt");
$json_obj = '{
"product": "Treats",
"price":"300"
}';

//convert to stdclass object


$c_data = json_decode($json_obj);

//store the element values into variables


$product = $c_data->product;
$price = $c_data->price;

//insert values into mysql database


$sql="INSERT INTO orders(product,price) VALUES ('$product', '$price')";

if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$retval = mysqli_query( $con, $sql );

if(! $retval ) {
die('Could not enter data: ' . mysqli_error($con));
}
echo "Entered data successfully\n";
mysqli_close($con);
echo "<a href=1.html>Back</a>";
?>

g) Code for Image 7(Doughnuts):

<?php
Subject: Applications of AWT Id: 21102047

$con =mysqli_connect("localhost", "root", "","awt");


$json_obj = '{
"product": "Doughnuts",
"price":"250"
}';

//convert to stdclass object


$c_data = json_decode($json_obj);

//store the element values into variables


$product = $c_data->product;
$price = $c_data->price;

//insert values into mysql database


$sql="INSERT INTO orders(product,price) VALUES ('$product', '$price')";

if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$retval = mysqli_query( $con, $sql );

if(! $retval ) {
die('Could not enter data: ' . mysqli_error($con));
}
echo "Entered data successfully\n";
mysqli_close($con);
echo "<a href=1.html>Back</a>";
?>

h) Code for Image 8(Candies):

<?php
$con =mysqli_connect("localhost", "root", "","awt");
$json_obj = '{
"product": "Candies",
"price":"150"
}';

//convert to stdclass object


$c_data = json_decode($json_obj);

//store the element values into variables


$product = $c_data->product;
$price = $c_data->price;

//insert values into mysql database


$sql="INSERT INTO orders(product,price) VALUES ('$product', '$price')";
Subject: Applications of AWT Id: 21102047

if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$retval = mysqli_query( $con, $sql );

if(! $retval ) {
die('Could not enter data: ' . mysqli_error($con));
}
echo "Entered data successfully\n";
mysqli_close($con);
echo "<a href=1.html>Back</a>";
?>

Output:
Subject: Applications of AWT Id: 21102047
Subject: Applications of AWT Id: 21102047

You might also like