0

Hello! I've created a script that allows you to create a 'page' by saving the relevant information to a MySQL database. One script will generate all of the pages that are created by the id # that is passed to said script. Of course.

When saving the page's information MySQL will auto-increment the ID # column by which the table is indexed. I want the first script, after successfully saving the page's data, to print the HTML link for the page's creator to use for linking to the created page.

I am not sure if there's anyway after opening the database and inserting the new row into the table if there's a way to easily reference the newly created ID # which MySQL created in the ID row.

If not...what way is generally used for such a purpose? I tried to make this as clear as I could but please let me know if I can offer any more information.

HINT - A valid link's target would be like: show_page.php?id=20

Thanks!

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by weekendrockstar
0

Thank yOu! I will mark this as "solved" but I wanted to show my solution for anyone that may stumble upon this.

mysql_query("INSERT INTO pages 
    (title, author, date, body) VALUES('$page_title', '$author', '$date', '$body') ") 
	  $inserted_id = mysql_insert_id();
	  echo "
	  Your page has been added!
	  <br /><br />
	  Click <a href=\"page.php?id=$inserted_id\">here</a> to view the new page

For brevity's sake I omitted the SQL die. And just to further clarify for anyone that was sent straight to this post via search engine I'll specify some of what was in my initial post:

This code was to make available the MySQL-created (auto-incremented) ID # for the new page that was being created.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.