Skip navigation
tokick4
Currently Being Moderated

invoice numbers

Feb 22, 2012 2:22 PM

Tags: #php #mysql #dreamweavercs5.5

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

 
Replies
  • Currently Being Moderated
    Feb 22, 2012 3:16 PM   in reply to tokick4

    >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.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 22, 2012 8:59 PM   in reply to tokick4

    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)
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 23, 2012 9:16 AM   in reply to tokick4

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points