Solved

PHP MYSQL INSERT Question

Posted on 2004-10-01
3
287 Views
Last Modified: 2008-03-10
ok this is a long shot...

i am inserting a row into a table. the table has an auto-id field.

is there a way to get the auto-id assigned to this record from the insert. does the insert return anything other than true/false or are there any other functions i can run on the query to get the value that has been assigned.

i want to basically be able to get the value of the ID field without having to requery the database.
the information i am inserting could be the same but the id will always be different. so i could have multiple rows of data that looks the same but the id is different for each.



0
Comment
Question by:Fatlog
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
minichicken earned 50 total points
ID: 12198842
you can use mysql_insert_id();

Example:

mysql_query ("insert into table values (....)"); //run your insert query first
$ID = mysql_insert_id(); //returns previous inserted ID from DB

j311y :)
0
 

Author Comment

by:Fatlog
ID: 12198910
thanks

thats perfect

didnt think i would get an answer to this one!!
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12198982
Good stuff :)
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

860 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