I'm trying to pass a value for on-screen analysis in the following situation:
The user fills in a form. When the form is submitted to the MySQL database, it is given an ID (performed by the table - it automatically increments new entry IDs).
When the user submits the Form (form.php), the information gets added to this database and the user gets sent to a "Thank You" page (thanku.php)
Is it possible to show the ID of that entry on the "Thank You" page? (i.e. "Thank you for your submission. Your ID is [ID]")
You would put $new_id=mysql_insert_id in the head if that's where your insert statement is. Like I said, you put it immediately following your insert.
I'm not sure what you mean by "at the appropriate anchor in the body" It depends on what you are trying to do with it.
Usually this function is used as follows: You are creating a new record but not all the data is going into the same table, You need to retrieve the id so you can use it as the foreign key for the subsequent table inserts.
Different unique IDs will be created for different users connected to the page.
It doesn't matter if you put it immediately after insert statement or not.
mysql_insert_id(RESOURCE) will always return the last insert ID made by that user only.
Example:
Let's say John entered your site and filled the form. If you can, theoretically, stop your PHP code for few hours between insert and mysql_insert_id staements, AND 100 people filled the form at that time, John will have same unique ID created by his own mysql session, not the last id of the whole table.
Slightly off topic but something for you to consider:
If the MySQL db is creating the insert_ID is it doing this sequentially - i.e. is it incrementing the ID each time a user adds a record? Does it create a security issue for you if the user knows what their ID is, for example, do you have a facility where the user enters the insert_ID to retrieve their info? It would be pretty simple to subtract 1 from your own insert_ID and see what someone else entered.
Tony
North America
Europe, Middle East and Africa
Asia Pacific