php

Invoice No Generating using Php Mysql

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>

i have attached the video link below. which will do this tutorials step by step.

 

admin

Recent Posts

Creating Grocery Inventory App Using React

Introduction to Grocery Inventory Apps Managing grocery inventory can be a daunting task, but with…

3 days ago

Fish Inventory Shop Management System in Angular

This article explain how to make a Fish Inventory Management App in Angular.this app explain…

1 week ago

Fish Inventory Management with React

Introduction to Fish Inventory Management In the aquaculture industry, managing fish inventory is crucial for…

1 week ago

Java GUI CRUD for Beginners

Introduction to Java GUI CRUD Java is a powerful programming language widely used for building…

1 week ago

Creating Beautiful Login Form Design Using React

Introduction to Login Form Design Designing an effective and beautiful login form is crucial for…

2 weeks ago

Creating Responsive Login Form with React

Introduction In today creating a responsive login form is essential for providing a seamless user…

2 weeks ago