By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,441 Members | 996 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,441 IT Pros & Developers. It's quick & easy.

Getting the ID of the last inserted row in MySQL via PHP...

P: 25
It's comming along well! I have decided to add a admin page where somebody could edit or delete a comment. I am on the editing part. I have a problem though, I need to post the data to the next form without a form. Make sense?

This is why.

When you edit a comment the comment will appear in the text box, you will then change it and submit and it will post to the server over the left comment. So I need to post the number of the comment so it knows which one to relpace and the actual comment that you clicked the edit under.

Thanks,
Matt.
May 24 '07 #1
Share this Question
Share on Google+
3 Replies


pbmods
Expert 5K+
P: 5,821
I'm going to go ahead and split this thread so your question gets better exposure :)

When you edit a comment the comment will appear in the text box, you will then change it and submit and it will post to the server over the left comment. So I need to post the number of the comment so it knows which one to relpace and the actual comment that you clicked the edit under.
So what you're looking for is the ID number of the previously-inserted comment. Is this correct?

You'll want to take a look at mysql_insert_id for that one.
May 24 '07 #2

P: 25
No not really, I already have a collumn in my database where it does an autoincrement. I just need to get that info and the comment over to the other page so you can edit it in a text box. It would look like this.

Hello!
Matthew
Hi, I like your page

Edit Delete

If you clicked on delete it would take that comment, the one you clicked to edit and take you to a new page where the comment would be posted inside a text box for you to edit, you click submit and it would replace the comment in the database, so I would need the number of the comment. I need to know how to post values without a form.

Thanks for All The Help,
Matt
May 24 '07 #3

pbmods
Expert 5K+
P: 5,821
No not really, I already have a collumn in my database where it does an autoincrement. I just need to get that info and the comment over to the other page so you can edit it in a text box.
Ah. So when a User submits a comment, you want to go to a new page that displays that comment, along with links allowing the User to edit and delete that comment.

What I would do in this case would be to pass the id of the comment in the URL. E.g.:

ThePageThatSavesTheComment.php:
Expand|Select|Wrap|Line Numbers
  1. header('Location: comment_preview.php?commentid=' . mysql_insert_id());
  2. exit;
  3.  
comment_preview.php:
Expand|Select|Wrap|Line Numbers
  1. $comment = mysql_query("SELECT * FROM `comments` WHERE `commentid` = '" . intval($_GET['commentid']) . "' LIMIT 1");
  2. .
  3. .
  4. .
  5. ?>
  6. <a href="comment_edit.php?commentid=<?php echo $_GET['commentid']; ?>">Edit</a>
  7.  
May 24 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.