You are on page 1of 4

Internet and Web Programming lab

LAB CAT EXAM


Submitted by: Jeevan Stephen thomas
19BCE2464

Question screenshot:

PROCEDURE:
• Create an html file to input the number of pencil , pen and eraser
• Create a php file to decrement the amount of pencil, pen and eraser from
the database and print the bill no
• Create a database store

Code:
Index.php

<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
<meta charset="utf-8">
<title>Department store</title>
<link rel="stylesheet" href="style.css">
<script src=script.js></script>
</head>

<body>
<center>
<h1>Department store</h1>
<br>
<br>
<h2>Enter the number of items</h2>
<br>
<form class="" action="stock.php" method="post" >
<table>
<tr>
<td>
<label>Pencil: </label>
</td>
<td>
<input type="number" name="pencil" value="" >
</td>
</tr>
<tr>
<td>
<label>Pen: </label>
</td>
<td>
<input type="number" name="pen" value="">
</td>
</tr>
<tr>
<td>
<label>Eraser: </label>
</td>
<td>
<input type="number" name="eraser" value="">
</td>
</tr>
</table>
<br>
<br>
<input type="submit" value="Submit"/>

</center>
</body>

</html>
Stock.php
<?php
session_start();

$server="localhost";
$username="root";
$password="";
$database="store";
$con=mysqli_connect($server,$username,$password,$database) or die("could not
connect");

if(isset($_POST['submit']))
{
// Get input
$pencil=mysqli_real_escape_string($con,$_POST['pencil']);
$pen=mysqli_real_escape_string($con,$_POST['pen']);
$eraser=mysqli_real_escape_string($con,$_POST['eraser']);

$query = "SELECT * FROM stock WHERE bill_no = max($bill_no);";


$result = mysqli_query($con,$query);

// Get results
while( $row = mysqli_fetch_assoc( $result ) ) {
// Get values
$bill_no = $row["bill_no"];
$pencil_stock = $row["pencil_stock"];
$pen_stock = $row["pen_stock"];
$eraser_stock = $row["eraser_stock"];

echo "bill no: {$bill_no}";


}
}
?>

Output Screenschot:

You might also like