phppup Posted December 5, 2022 Share Posted December 5, 2022 I am using the procedural method to insert data with a prepared statement. Can someone please give me the correct format to obtain the last inserted id number under these conditions. Just plugging simple form data into a table and want to echo a message stating "the record was successfully inserted as number $last_input" Quote Link to comment https://forums.phpfreaks.com/topic/315615-last-insert-id-for-procedural-statement/ Share on other sites More sharing options...
ginerjm Posted December 6, 2022 Share Posted December 6, 2022 Using PDO? Quote Link to comment https://forums.phpfreaks.com/topic/315615-last-insert-id-for-procedural-statement/#findComment-1603282 Share on other sites More sharing options...
phppup Posted December 6, 2022 Author Share Posted December 6, 2022 (edited) @ginerjm if you read my post, I think it (and the headline title) indicate PROCEDURAL method in fairly clear terms. Edited December 6, 2022 by phppup Typos Quote Link to comment https://forums.phpfreaks.com/topic/315615-last-insert-id-for-procedural-statement/#findComment-1603284 Share on other sites More sharing options...
ginerjm Posted December 6, 2022 Share Posted December 6, 2022 Procedural can be using mysqli or pdo. Think about it. Quote Link to comment https://forums.phpfreaks.com/topic/315615-last-insert-id-for-procedural-statement/#findComment-1603285 Share on other sites More sharing options...
phppup Posted December 6, 2022 Author Share Posted December 6, 2022 Using MySQLi Quote Link to comment https://forums.phpfreaks.com/topic/315615-last-insert-id-for-procedural-statement/#findComment-1603286 Share on other sites More sharing options...
Solution maxxd Posted December 6, 2022 Solution Share Posted December 6, 2022 Try https://www.php.net/manual/en/mysqli.insert-id.php. I'll skip the obligatory advice to switch to PDO for the moment. Quote Link to comment https://forums.phpfreaks.com/topic/315615-last-insert-id-for-procedural-statement/#findComment-1603288 Share on other sites More sharing options...
phppup Posted December 6, 2022 Author Share Posted December 6, 2022 (edited) 2 hours ago, maxxd said: Try https://www.php.net/manual/en/mysqli.insert-id.php I used this printf("New record has ID %d.\n", mysqli_insert_id($conn)); The good news is: it provided a result The bad news: I have no idea why it works. What does %d signify and where is it generated from? 2 hours ago, maxxd said: I'll skip the obligatory advice to switch to PDO Thank you so much!!! Edited December 6, 2022 by phppup Typos Quote Link to comment https://forums.phpfreaks.com/topic/315615-last-insert-id-for-procedural-statement/#findComment-1603289 Share on other sites More sharing options...
phppup Posted December 6, 2022 Author Share Posted December 6, 2022 Now I got it. Researched printf and made sense of it all. Quote Link to comment https://forums.phpfreaks.com/topic/315615-last-insert-id-for-procedural-statement/#findComment-1603295 Share on other sites More sharing options...
Barand Posted December 6, 2022 Share Posted December 6, 2022 18 hours ago, ginerjm said: Procedural can be using mysqli or pdo. There must be some pages missing from the PDO section of my copy of the manual. Quote Link to comment https://forums.phpfreaks.com/topic/315615-last-insert-id-for-procedural-statement/#findComment-1603301 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.