Increment a Number Field - Post ID...

User 2320719 Photo


Registered User
3 posts

Hi,

I have a booking form that I would like to add a field to that increments itself by 1 on each submission, so that I can tie that number to a record in a SQL database, it would also give the form poster an official record number of the original posted form should they wish to modify or cancel the original booking. (hope that makes sense?)

Is this possible?

I am currently in the testing/making a lot of changes phase, so the form is not in production as such. What I currently have does work, the form currently posts data to a test SQL database, any help or pointers greatly appreciated, thank you.

Alan
User 187934 Photo


Senior Advisor
20,181 posts

Hi Alan,
Yes what I would do is count the submissions in the database.
Something like this to count form submissions.
$sql = "SELECT count(recordnumber) FROM tablename";
$result = $pdo->prepare($sql);
$result->execute();
$submissioncount = $result->fetchColumn();
$newcount = $submissioncount + 1;


Now you can place the $newcount into the inputs value attribute.
<input name="recordnumber" type="number" value="<?php echo $newcount ;?>" />

This setup requires setting up your host to parse php inside html. Otherwise change your formname.html to formname.php
Let me know if you need some more assistance.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2320719 Photo


Registered User
3 posts

Hi Eric,

Thank you for the prompt response. Firstly I am not really that familiar with SQL, so treat me as a total newbie, are you saying that is what I need to do, or are you saying that is what I could do?

The reason I ask is that at the moment I am building and testing the form as I go along step by step, mainly so that if I screw up I know exactly what I have screwed up and can trouble shoot just one thing. At the moment my submitted forms are going into a test database, so would I be able to add the code for the increment count to the form structure now? or can I only add the incremental count during form processing via code like you have added above on my server doing the incremental numbering addition to the final form output? (jeez that sounds complicated, I hope I am asking the right questions?

Thank you
User 187934 Photo


Senior Advisor
20,181 posts

Here's a quick example.
https://ericrohloff.com/coffeecup/ccfor … -count.php
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2320719 Photo


Registered User
3 posts

Hi Eric,

Thank you, let me try to get my head around what you have done and I will reply.

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.