Slip 22 - C) Write a PHP program to create a shopping mall UI. User must be allowed to do purchase from two pages. Each page should have a page total. The third page should display a bill, which consists of a page total of whatever the purchase has been done and print the total. (Use http session tracking).

Solution:

1.php-

<?php
session_start();
if(!isset($_SESSION['total']))
{
$_SESSION['total']=0;
}
if(isset($_POST['submit']))
{
$_SESSION['pname']="KACHI GHANI MUSTARD OIL (L)";
$_SESSION['amt']="100";
$_SESSION['total']=$_SESSION['total']+100;
}
?>
<html>
<head>
</head>
<body>
<h1<center>shopping mall</center> Total :<span style="color:red<?php if(isset($_SESSION['total'])){echo $_SESSION['total'];}?></span</h1>
<table style="width:100%">
<tr>
<th><a href="1.php">1</a></th>
<th><a href="2.php">2</a></th>
<th><a href="3.php">3</a></th>
<th><a href="Final.php">Final</a></th>
</tr>
</table>
Product 1:
<FORM ACTION="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
<table style="width:100%" border=1>
<tr>
<th>Product Image</th>
<th>Product Name</th>
<th>Price </th>
<th>action</th>
</tr>
<tr>
<th><img src="img/1.png"height="200" Width="200"> </th>
<th>KACHI GHANI MUSTARD OIL (L)</th>
<th>100</th>
<th>
<input type=submit name=submit value="buy">
</form></th>
</tr>
</table>
</body>
</html>

2.php-

<?php
session_start();
if(!isset($_SESSION['total']))
{
$_SESSION['total']=0;
}
if(isset($_POST['submit']))
{
$_SESSION['pname']=$_SESSION['pname'].","."Patanjali Saundarya Face WashOIL (L)";
$_SESSION['amt']=$_SESSION['amt'].","."50";
$_SESSION['total']=$_SESSION['total']+50;
}
?>
<html>
<head>
</head>
<body>
<h1<center>shopping mall</center> Total :<span style="color:red;"><?php if(isset($_SESSION['total'])){echo $_SESSION['total'];}?></span></h1>
<table style="width:100%">
<tr<br> <th<a href="1.php">1</a</th>
<th<a href="2.php">2</a</th>
<th><a href="3.php">3</a></th>
<th<a href="Final.php">Final</th>
</tr>
</table>
Product 2:
<FORM ACTION="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
<table style="width:100%" border=1>
<tr>
<th>Product Image</th>
<th>Product Name</th>
<th>Price </th>
<th>action</th>
</tr>
<tr>
<th><img src="img/2.jpg"height="200" Width="200"> </th>
<th>Patanjali Saundarya Face Wash</th>
<th>50</th>
<th>
<input type=submit name=submit value="buy">
</form></th>
</tr>
</table>
</body>
</html>

3.php-

<?php
session_start();
if(!isset($_SESSION['total']))
{
$_SESSION['total']=0;
}
if(isset($_POST['submit']))
{
$_SESSION['pname']=$_SESSION['pname'].","."Patanjali mango juices";
$_SESSION['amt']=$_SESSION['amt'].","."70";
$_SESSION['total']=$_SESSION['total']+70;
}
?> <html>
<head>
</head>
body>
<h1><center>shopping mall<</center> Total <span style="color:red;"><?php if(isset($_SESSION['total'])){echo $_SESSION['total'];}?></span></h1>
<table style="width:100%">
<tr>
<th><a href="1.php">1</a></th>
<th><a href="2.php">2</a></th>
<th><a href="3.php">3</a></th>
<th><a href="Final.php">Final</a></th>
</tr>
</table>
Product 3:
<FORM ACTION="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
<table style="width:100%" border=1>
<tr> <th>Product Imag</th>
<th>Product Name</th>
<th>Price </th>
<th>action</th>
</tr<br> <tr>
<th<img src="img/3.jpg"height="200" Width="200"> </th>
<th>Patanjali mango juices</th>
<th>70<</th>
<th>
<input type=submit name=submit value="buy" >
</form>
</tr>
</table>
</body>
</html>

final.php

<?php
session_start();
?>
<html>
<head>
<script>
function myFunction()
{
window.print();
}
</script>
</head>
<body>
<h1><center>shopping mall</center> Total :<span style="color:red<?php if(isset($_SESSION['total'])){echo $_SESSION['total'];}?></span> <table style="width:100%">
<tr>
<th<a href="1.php">1</a></th>
<th<a href="2.php">2</a</th>
<th<a href="3.php">3</a></th>
<th><a href="Final.php">Final</a></th>
</tr>
</table>
<br>
<br>
<h2><center>Final Bill</center> Total :</h2>
<table style="width:100%" border=1>
<tr>br> <th>Product Name</th>
<th>AMount /th>
<th>Total</th>
<th>Print</th>
</tr>
<tr>
<th><?php if(isset($_SESSION['pname'])){echo $_SESSION['pname'];}?></th>
<th><?php if(isset($_SESSION['amt'])){echo $_SESSION['amt'];}?></th>
<th><span style="color:red;"><?php if(isset($_SESSION['total'])){echo $_SESSION['total'];}?></span></th>
<th><button onclick="myFunction()">Print </button>
</tr>
</table>
</body>
</html>

note-create an img folder to an save images whatever
o/p-
click on final button then print report

Post a Comment

0 Comments