Reputation: 21
I have a script which calculates a quote based on values within database.
I need a simple bit of PHP code to show a number and add 1 to it each time the form is submitted.
For example, Joe Bloggs gets a quote, and quote reference number 111 is shown on gthe screen.
The next time the form is submitted it will show 112 on screen and so on.
What is the best code to use to achieve this?
Upvotes: 0
Views: 7549
Reputation: 7155
PHP has nothing to do with AUTO_INCREMENT
MySQL attribute.
Just apply AUTO_INCREMENT
to field you want and when inserting data, insert data to every field except AUTO_INCREMENT
fields. MySQL will do that automatically for you.
To display latest number of your AUTO_INCREMENT
field - use mysql_insert_id()
or see this article.
Upvotes: 0
Reputation: 735
You should really think about an auto-increment id column in your database. http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html
As an alternative you can write the number into a file with php...
Upvotes: 2