Solved

PHP MYSQL INSERT Question

Posted on 2004-10-01
3
274 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now