Skip to main content
Participant
February 22, 2012
Question

invoice numbers

  • February 22, 2012
  • 2 replies
  • 1168 views

Can anyone tell me how to make invoice number on a form to appear on the form using php.  I cannot remember how to pull the number from MySQL primary id auto increment.  I have a invoice form to take data and put into the database.  I want to display the next available number from the database.

Thanks

Jon

This topic has been closed for replies.

2 replies

February 23, 2012

Here is a simple workaround:

  1. Add 2 new fields in your database table(you can change the names as you like):
    • form_date DATE
    • form_status ENUM('1','0') DEFAULT 0
  2. One time only, update your current records and set the form_status to 1 to prevent them being purged. (UPDATE table_name SET form_status = 1)
  3. Insert a new empty record, get the last insert id and display it in the form. Also add that id into the from with a hidden field
  4. In receiving page, if the form entries are correct, update the table with new information and set the form_status to 1.
  5. Optionally in the receiving page, you can write a simple script that purges the incomplete forms older than XX days (e.g. DELETE FROM table WHERE form_date < 'YYYY-MM-DD' AND form_status = 0)
Participating Frequently
February 22, 2012

>I have a invoice form to take data and put into the database.

>I want to display the next available number from the database.

So you want to display the next available number as the invoice number on the form? That's got potentially serious problems. What if two users access the form? User A will get the same 'next available number' as user B. You're better off providing the invoice number only after the update occurs.

tokick4Author
Participant
February 23, 2012

How could I post the insert and then post back to another page all the info to print the invoice with number?

Participating Frequently
February 23, 2012

After inserting the row into the database, use the php function mysql_insert_id() to retrieve the invoice number to display for the user to print.