Solved

Pass Dreamweaver PHP Insert Form data to new page

Posted on 2012-03-16
5
715 Views
Last Modified: 2012-03-18
Using Dreamweaver and PHP.

On page one, I have an Insert Form with one Field (LastName) which inserts into a SQL database. The SQL database has an auto-increment ID field.

When I click on Submit (thereby inserting the data into the database), I want a new page to open up and display the value of the ID field.

I have read numerous posts online suggesting use of mysql_insert_id(), etc., but no matter where I put that function, I get a blank field on the next page.

I have a session variable sessMemberNumber, so I tried

<?php $_SESSION['sessMemberNumber'] = mysql_insert_id();?>

I tried putting this on page 1 after the INSERT query. I tried putting it on page 2 after the Start Session command.

Nothing seems to work.

Can someone give me the simplest possible code to perform this task? And exactly where to place it in my code?

NOTE: I have successfully used User Authentication forms to send session variables from one page to another, but can't figure out how to do this with an INSERT Form.
0
Comment
Question by:PaBirds
  • 3
5 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37731002
It must be placed immediately after the query that does the insert.  It won't work before.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37731005
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 37731145
Post the Insert Record code block that Dreamweaver generates and either Dave or I will show you exactly where the mysql_insert_id() function goes.  

It has to go after the insert operation but BEFORE the code that redirects the user to the next page.
0
 

Author Comment

by:PaBirds
ID: 37732463
Attached is the code from the first page. (testForm1)
TestForm1.txt
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 37733200
If that's the file you're talking about, it goes right after the 'insert' query like this.

$Result1 = mysql_query($insertSQL, $PaSiteGuide) or die(mysql_error());
$_SESSION['sessMemberNumber'] = mysql_insert_id();

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
If your app took Google’s lash recently, here are the 5 most likely reasons.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now