Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP MYSQL INSERT Question

Posted on 2004-10-01
3
Medium Priority
?
304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
minichicken earned 200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 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