drewbix Posted March 25, 2012 Share Posted March 25, 2012 Hi everyone, I'm self taught and still learning. I have this code working just the way I want, but I feel like there must be a more efficient way of doing it. Basically my php document uses if ($_SERVER['REQUEST_METHOD'] == "POST"), then I collect a bunch of values from the form, connect to the database and insert them. Then just below that on the same page if the insert is successful, I want to have a link to now view the entry we just did, so I use this code: $query = "SELECT * FROM entry ORDER BY ID DESC limit 0, 30"; $result=mysql_query($query) or die ( mysql_error() ); $entryID=mysql_result($result,0,"ID"); echo '<p><a href="view.php?id=' . $entryID . '" target="_blank">View your entry</a></p>'; It seems like there should be a way to know the ID without doing a new query, and I wonder if it might present problems if people insert entrys at the same time or something like that, I'm not sure exactly. Hopefully this makes sense, do you guys have any recommendations? Quote Link to comment https://forums.phpfreaks.com/topic/259703-is-there-a-better-way-to-do-this/ Share on other sites More sharing options...
scootstah Posted March 25, 2012 Share Posted March 25, 2012 mysql_insert_id Quote Link to comment https://forums.phpfreaks.com/topic/259703-is-there-a-better-way-to-do-this/#findComment-1331013 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.