Link to home
Start Free TrialLog in
Avatar of 3xtr3m3d
3xtr3m3d

asked on

need idea

Hi

Im making a invoice system and my client needs invoice numbers in a order like 1,2,3,4 etc...

what i did was add a button to get new invoice then using ajax return last invoice number and add +1 to that number and save

problem is if two people use system at same time there is a possibility that both will get same number :(

what is the best way to solve this ?

Sorry for my bad english, hope someone will understand what i meant

Thanks
Avatar of Lee
Lee
Flag of United Kingdom of Great Britain and Northern Ireland image

Generate the invoice number when the record is saved rather than when you open a new page to create one.
Avatar of 3xtr3m3d
3xtr3m3d

ASKER

is there a  easy way to insert and return the id of that inserted record [id=autoincrement]?

currently im doing in this way

SELECT ID FROM tblinvoice ORDER BY ID DESC LIMIT 1
SELECT MAX(ID) FROM tblinvoice is a good method
ASKER CERTIFIED SOLUTION
Avatar of Greg Alexander
Greg Alexander
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry guys, I did not refreshed the page
galexander07 , OP_Zaharin  thanks for the information seems like best way is use mysql_insert_id()

Thanks all for the support.
NP, glad to help!
no prob 3xtr3med :)