pizzaguy Posted March 18, 2011 Share Posted March 18, 2011 For a user registration page I'm making, I have this query to insert the new user's information into the database INSERT INTO users (email,password,public_url,first_name,last_name) VALUES ('$email','$encypted','$URL','$firstName','$lastName') LIMIT 1; Is it possible to also have the query response either return the whole row, or act as though I'm also including "SELECT uid"? Basically, "uid" is my auto_incrementing value, and I want to know if it's possible to access this without having to perform a separate SQL query? It just seems redundant to insert values, and then search for those values again. Link to comment Share on other sites More sharing options...
thescientist Posted March 18, 2011 Share Posted March 18, 2011 I suppose you could just test the value of the query after you execute it, and if it was successful, just reuse the same values you just inserted.Other than that, depending on the database, you might be able to use stored procedures and have it return the record. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 18, 2011 Share Posted March 18, 2011 If you're using PHP and MySQL, you can use this function to get the autoincrement ID for the last row inserted:http://www.php.net/manual/en/function.mysql-insert-id.php Link to comment Share on other sites More sharing options...
birbal Posted March 18, 2011 Share Posted March 18, 2011 mysql_insert_id() will return the last inserted id of auto-incremented field Link to comment Share on other sites More sharing options...
pizzaguy Posted March 18, 2011 Author Share Posted March 18, 2011 Thank you! mysql_insert_id is just what I was looking for. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.