Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

invoice numbers

New Here ,
Feb 22, 2012 Feb 22, 2012

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

TOPICS
Server side applications
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 22, 2012 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 22, 2012 Feb 22, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 23, 2012 Feb 23, 2012
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 22, 2012 Feb 22, 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)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines