hi friends,

I used following code for automatically incrementing value and stored in database. This working but it have small problem. when I submit value then only incrementing. ex, i entered details for invoice number 2, but it showing invoice number 1.

 <?php

       mysql_connect("localhost","root","") or die(mysql_error());
   mysql_select_db("menus") or die(mysql_error());
   $query2=mysql_query("select invoiceno from bill");

    while($row=mysql_fetch_array($query2))
      {
       $var=$row['invoiceno'];
      }
     $count=$var+1;
     echo $count;

  ?>

anybody knowing result for pls help to me.

Recommended Answers

All 2 Replies

select max(invoiceno) from bill
OR
You may set invoiceno column to AUTO_INCREMENT in MYSQL, it will automatically insert new id.

Member Avatar for rajarajan2017

Use AUTO_INCREMENT/ Primay key for the invoice number field. That is a structure way to maintaining table with unique id. While setting primary key for invoice number, it automatically checks for the duplication and never allowed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.