Solved

Get current id from MySQL post/query?

Posted on 2009-05-09
2
418 Views
Last Modified: 2013-12-12
Hi Experts!

In the same PHP file I want to:

1. I want to create a new user and post it to the database (that code is already created)

2. echo the user id for that new user.

How can I do that?

I could find out the highest user id from the database and echo that, but it doesnt feel 100% safe.

Is there a way to find out the "current" id that was posted at that moment?

Thanks in advice!
0
Comment
Question by:GodDoesntExist
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24344086
presuming that your table has auto_increment, learn about the LAST_INSERT_ID() function of mysql:
http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html

resp: the php shortcut function mysql_insert_id:
http://lu2.php.net/mysql_insert_id

that's 100% safe.
0
 
LVL 3

Author Closing Comment

by:GodDoesntExist
ID: 31579773
Thank you!

Perfect solution!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
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…
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…

747 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

11 Experts available now in Live!

Get 1:1 Help Now