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

Registration with image upload Java Jdbc(Download Source code)

Introduction In this section, we will guide you step by step in the development of an image upload registration system in Java using MySQL and JDBC. In the application, users register…

1 week ago

Touchable shop Pos system using Java

The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…

4 weeks ago

Build Your First Responsive Login Form Using HTML and CSS FlexBox

Creating a responsive login form is a crucial skill for any web developer. In this…

1 month ago

Build Crud API with Laravel 12

In this tutorial will teach  Laravel 12 CRUD API  by step. Laravel  10 CRUD Application …

1 month ago

laravel 12 image upload tutorial

In this lesson we talk about laravel 12 image uploading and display the image step…

1 month ago

Laravel 12 CRUD Application

In this tutorial will teach Laravel 12 CRUD Application step by step. Laravel  12 CRUD…

1 month ago