This tutorial will teach you how to do auto generate Invoice No using Php Mysql step by step
i attached full source code below.i explained more clearly in the video tutorial attached below.
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "minventory";
$conn = mysqli_connect($servername,$username,$password,$dbname);
?>
<?php
$query = "SELECT invoiceid FROM sales ORDER BY invoiceid DESC";
$result = mysqli_query($conn,$query);
$row = mysqli_fetch_array($result);
$lastid = $row['invoiceid'];
if(empty($lastid))
{
$number = "E-0000001";
}
else
{
$idd = str_replace("E-", "", $lastid);
$id = str_pad($idd + 1, 7, 0, STR_PAD_LEFT);
$number = 'E-'.$id;
}
?>
<?php
if($_SERVER["REQUEST_METHOD"]== "POST")
{
$invoiceid = $_POST['invoiceid'];
$prodname = $_POST['prodname'];
$price = $_POST['price'];
if(!$conn)
{
die("connection failed " . mysqli_connect_error());
}
else
{
$sql = "insert into sales(invoiceid,prodname,price)VALUES('".$invoiceid."','".$prodname."','".$price."') ";
if(mysqli_query($conn,$sql))
{
$query = "SELECT invoiceid FROM sales ORDER BY invoiceid DESC";
$result = mysqli_query($conn,$query);
$row = mysqli_fetch_array($result);
$lastid = $row['invoiceid'];
if(empty($lastid))
{
$number = "E-0000001";
}
else
{
$idd = str_replace("E-", "", $lastid);
$id = str_pad($idd + 1, 7, 0, STR_PAD_LEFT);
$number = 'E-'.$id;
}
}
else
{
echo "Record Faileddd";
}
}
}
?>
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</head>
<body>
<div class="row">
<div class="col-sm-4">
<form action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="post">
<div align="left">
<h3>invoice no generating </h3>
</div>
<div align="left">
<label>Invoice No</label>
<input type="text" class="form-control" name="invoiceid" id="invoiceid" style=" font-size: 16px; color: blue; font-weight: bold; " value="<?php echo $number; ?>" readonly >
</div>
<div align="left">
<label>Productname</label>
<input type="text" class="form-control" name="prodname" id="prodname" >
</div>
<div align="left">
<label>Price</label>
<input type="number" class="form-control" name="price" id="price" >
</div>
</br>
<div align="left">
<input type="submit" value="ADD" class="btn btn-success">
</div>
</form>
</div>
</div>
</body>
</html>
What Is the Tesla Pi Phone? Imagine if Tesla, the company that makes famous…
Inventory Management POS systems are now an essential part of modern businesses such as bookshops,…
If you're just beginning to learn Java GUI programming creating an Water System Calculator is a fantastic project for…
GitHub is a powerful tool used by teams and developers around the globe. This guide is…
It's like having a super-smart buddy that is always there to help you write stories,…
The UK is known for its rich history, diverse culture, and most of all its…