Wesley Smith
Wesley Smith

Reputation: 19571

generate and save sequential number on POST

I have a form that uses Post to send info to a PHP page.

The PHP page;

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;

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.

Upvotes: 0

Views: 915

Answers (1)

PGallagher
PGallagher

Reputation: 3113

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.

enter image description here

If you're using mysqli for your mysql database interaction (as you perhaps should be), then you can then retrieve this autonumber using;

$PassedRequestID = $mysqli->insert_id

Then pass this to your next page.

You will then need to query your database with something like (psuedo code);

SELECT Accounts.*, Requests.*
INNER JOIN Requests ON Requests.AccountID = Accounts.AccountID
WHERE Requests.RequestID = $PassedRequestID

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/

Upvotes: 1

Related Questions