473,509 Members | 3,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

25 New Member
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
3 5354
pbmods
5,821 Recognized Expert Expert
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
rcmatt4321
25 New Member
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
5,821 Recognized Expert Expert
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

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

Similar topics

3
5847
by: Carlos Marangon | last post by:
Hello! I need some help. How can I recall the last 5 rows from a MySQL table and show them? Where is the FAQs of this newsgroup? Sincerely,
3
2220
by: hshen | last post by:
Hi All, I have encountered a weird behavoir of embedded MySQL. Through a simple program I made (in Delphi 6), I can insert rows to a table through embedded MySQL and I can retrieve the rows from...
6
1999
by: Jeff Harbin | last post by:
I've spent the last 2 days trying to begin using mysql. I've purchased 3 books and read huge chunks of the documentation provided with the mysql zip file. I've downloaded...
1
37517
by: George Hill | last post by:
Hi I am trying to import several master detail records from files to ms sql server. I have orders file and order_items file that has several rows for each order. If I insert programmatically...
4
3250
by: Ike | last post by:
Is there a way in mysql to discern when the last date/time a field, row, or table was been updated or inserted? Thanks, ike
2
7545
by: mgarriss | last post by:
Given this table: CREATE TABLE test ( id SERIAL, example TEXT ); An implicit sequence is created as show in this message: NOTICE: CREATE TABLE will create implicit sequence 'test_id_seq'...
1
15910
by: Steve Leferve | last post by:
Hey folks - I have some VBA code for creating a row and related sub-rows from a 'wizard' form. I'm using sql 'INSERT' statements to create the rows. My problem is that I need to get the...
3
2583
by: Mark | last post by:
I'm using ASP.Net to accress a database, what I need to do is get the fields out of the very last record in the db. How do I do this? Actually I'm after the primary key, titled 'AdID' it'll tell...
2
3077
by: saifmsg | last post by:
Hello everyone, I am using a custom php class where i have wrapped all the mysql connection settings and query functions. Instead of calling direct mysql functions i creat an instance of this...
1
3015
davydany
by: davydany | last post by:
Hey guys...a n00b Here for this site. I'm making a sequence class for my C++ class. And The thing is in the array that I have, lets say i put in {13,17,38,18}, when i see the current values for the...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.