Solved

Get current id from MySQL post/query?

Posted on 2009-05-09
2
459 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
[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 Comments
 
LVL 143

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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.
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 …

726 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