I have a form that uses Post to send info to a PHP page.
The PHP page;
- Takes the form info.
- Rearranges it.
- Formats it.
- Then turns it into a code string that’s ultimately sent to another
page and performs some tasks using that info.
Form Code:
<form method="post" action="_php/buildMyPNR.php" name="GuestInfo"
onSubmit="return validateFormMethod1();">
<input type="text" name="AccountNumber" id="BID"
onkeypress="return isNumberKey(event)" size ="16"/>
<input type="hidden" name="requestID" id="RID" value="" />
..... bunch of other fields
<input type="submit" name="loadURL" id="submit" value="Submit"
onsubmit="return ValidateFields();" />
</form>
What I need to do is;
- Generate a sequential number each time the page is used.
- Pass that number with the post request (Sort of like a serial number
for the request), to another form say _php/buildMyPNR.php. - When _php/buildMyPNR.php loads, save the values of
AccountNumber and requestID to a database or similar. - Ultimately it would move on to _php/usageSummary.php, where the user can click
a button to return a list of AccountNumbers paired with the
requestID that was generated for the request. - Possibly download the list in an excel spreadsheet format, but it is
not absolutely necessary.
What would be the best way to accomplish this?
Mainly I need help with generating the requestID. I need them to be sequential so I assume that I would need to start with a number in my database like 00001, query that number from my form, add 1 to the returned value, then save the new value along with the AccountNumber when submit is pressed.
I have no experience with databases and any guidance would be greatly appreciated.
Ideally we’d see some schema and examples of code you’ve already tried…
However, you can use an Auto Increment field in your Database Table, which will accomplish the ID incrementing for you.
If you’re using mysqli for your mysql database interaction (as you perhaps should be), then you can then retrieve this autonumber using;
Then pass this to your next page.
You will then need to query your database with something like (psuedo code);
For exporting to Excel, if you search for PHP export CSV using Google, there’ll be plenty of examples there to choose from. However, as an example;
http://code.stephenmorley.org/php/creating-downloadable-csv-files/