473,385 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to get a value of an autoincrement id after insert in mysql

Hello,

Is there any way to find out the value of the id (wich is autoincrement)
when using the following statements:

$query = "INSERT into rfc values
('','$gebruiker','$omschrijving','$reden','$aanspr eekpunt')";
$sql = mysql_query($query) or trigger_error(mysql_error(), E_USER_WARNING);


Jul 17 '05 #1
3 2649

"heldopsokken" <fietsbelbellen@$#@NO******@hotmail.com> wrote in message
news:40*********************@news.xs4all.nl...
Hello,

Is there any way to find out the value of the id (wich is autoincrement)
when using the following statements:

$query = "INSERT into rfc values
('','$gebruiker','$omschrijving','$reden','$aanspr eekpunt')";
$sql = mysql_query($query) or trigger_error(mysql_error(),

E_USER_WARNING);

For MySQL at least, there's http://www.php.net/mysql_insert_id
as in :
$id=mysql_insert_id();

Garp
Jul 17 '05 #2
heldopsokken wrote:
Is there any way to find out the value of the id (wich is autoincrement)
when using the following statements:

$query = "INSERT into rfc values
('','$gebruiker','$omschrijving','$reden','$aanspr eekpunt')";
$sql = mysql_query($query) or trigger_error(mysql_error(),
E_USER_WARNING);


Use the mysql_insert_id() function which can be found in the MySQL section
of the manual at http://www.php.net/mysql_insert_id

In a MySQL query string you can also use "SELECT LAST_INSERT_ID()"

Both of these return the id generated from the most recent insert query.

--
Chris Hope
The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #3
Thanks a lot!

"Garp" <ga***@no7.blueyonder.co.uk> wrote in message
news:Ae******************@news-text.cableinet.net...

"heldopsokken" <fietsbelbellen@$#@NO******@hotmail.com> wrote in message
news:40*********************@news.xs4all.nl...
Hello,

Is there any way to find out the value of the id (wich is autoincrement)
when using the following statements:

$query = "INSERT into rfc values
('','$gebruiker','$omschrijving','$reden','$aanspr eekpunt')";
$sql = mysql_query($query) or trigger_error(mysql_error(),

E_USER_WARNING);

For MySQL at least, there's http://www.php.net/mysql_insert_id
as in :
$id=mysql_insert_id();

Garp

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andrew Rothwell | last post by:
Hello List, I have a movies database, that I had an autoincrementing field for counting purposes.What I did though was remove some of the rows out of the table, now my table is reporting an...
5
by: Mary Walker | last post by:
Hi, I'm enclosed a snippet of test code which highlights my problem. The Stored procedure insertValue should insert text into the parent, then insert other text into the child table but the 2...
5
by: JC Voon | last post by:
Hi: How to reset the autoincrement value generated by DataTable ? I've master and detail table, the detail table has a autoincrement column, each time i add a new master record, i need to...
5
by: Serdge Kooleman | last post by:
i have a query: select id, name from Dictionary field "id" is uniqueidentifier (primary key id is not null, and not identity !) i show only "name" in the dataGrid how to set up new id when i...
17
by: adburne | last post by:
Hi I'm a newbie in postgresql, I came from MSSQL, MySQL and now I'm testing postgres. In mysql there is a way to make a second autoincrement field, just: create table table1 (field1 integer,...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
0
by: vanisathish | last post by:
Hi, I'm facing a strange intermittent problem. I've my mySQL server running & another process updating a table continuously. One of the field in the table is Auto-Increment. When my PC is...
3
by: rajeevbadgujar | last post by:
Hello friends, I am using Hibernate and MySQL as backend. I am inserting customer data in table and generating customer id using autoincrement property of MySQL. Now after inserting I want to...
4
by: reshmaah | last post by:
hi iam interested in generating a variable value by autoincrementing, in CGI using c as user enters some data, i want to generate an index for it, and store in a binary file with data, as...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.