Home php Invoice No Generating using Php Mysql

Invoice No Generating using Php Mysql

5 min read
0
0
3,474

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.

 

Load More Related Articles
Load More By admin
Load More In php

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also

Inventory management system using React

In today’s fast-paced business environment, an efficient inventory management system…