Skip to main content
January 9, 2013
Question

Auto Increment Field and POST data

  • January 9, 2013
  • 1 reply
  • 2696 views

First off, thanks to everyone for your help here on this forum....it is very valuable.

My question today is about grabbing an Auto Increment field in POST data.

If someone fills out a form, then clicks on the button to submit the form (and open a new form detailed in the Action), I have some questions about the POST data from the first form:

If the table data I am collecting is StudentData, in the StudentData table is an Auto Increment field StudentID.   If I am having the person fill in the name and address fields etc, then click submit, how do I get StudentID on the next form through POST?

It seems to me that the table is not updated until they click the button right?  So how can I POST a piece of data that isnt available until AFTER they click that button?

Here is what I am asking:

Page1, Form1 = Data Insert into StudentData table using Dreamweaver's Insert>Data Objects > Insert Record > Insert Record Wizard.  Here is the form action code:

<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">

In Page1, I am using a recordset called rsStudentData.

Within the StudentData table is an auto increment field "StudentID".  In the query that creates rsStudentData, I have not selected the StudentID field at all.

Page2:  How do I grab the POST data for the StudentID field?  I have not used in the the Recordset of Page1, so how can I grab the field?

I appreciate any help you can provide!

-CL

This topic has been closed for replies.

1 reply

Participating Frequently
January 9, 2013

Assuming you are using MySQL, use one of these functions as determined by your connection type.

mysql_insert_id(); ----with  mysql connection

lastInsertId()  ----with a PDO connection

January 9, 2013

Thanks once again bregent....

I am trying to figure out where to put that - should I set it up as a variable on page 1 form 1  like this:

$passid = mysql_insert_id();

Where might it go?  It looks like it needs to  go in Page 1, right after the INSERT INTO statement right?  

If I set it up as above, will $passid be passed/available as POST data?

Participating Frequently
January 11, 2013

>Where might it go?  It looks like it needs to  go in Page 1,

>right after the INSERT INTO statement right?  

Yes, you need to execute it right after the insert has executed.

>If I set it up as above, will $passid be passed/available as POST data?

How are you getting from page1 to page2. A redirect after the insert? There is no posted data on a redirect. You either need to put it in the querystring, or set a session variable.