Hello, in this video, I am going to cover how to get the ID of the last inserted row. So what we've got here just insert a row and qaddafi the Sith Lord. So it's got a bunch of them here. And we want to get the ID. So this is useful for several different things. One, we might be inserting it then navigating to another page.
And for example, let's say to do, you're on a website, you are blogging, or it's a blog website, you click enter, or you click Submit, for the blog post, and it's common practice for the website to take you to that new blog post has been successfully inserted. And it would based on the ID so you could have a blog post page, which takes maybe you know, a get variable that you're passing through, you know, the form would be done as an action and a method and then the data ID can be used to retrieve The data to get is really simple. All you do is a connection or you know, whatever the name of the connection is last insert ID function. And then that's it. We're going to assign that to last i do and i think that you just added a row ID, then dollar sign, like so.
And I will a new line tab there. So as you can see, it should be 13. So if I reload it, we get you have just added a new row with the ID of 13. We load as you can see right there, and if I keep reloading it will just keep incrementing it because he keeps adding rows. So that is how you get the ID of the last insert. wrote, you can do whatever you want with it.
You could send the user to another page, send that Id with the user. You could maybe insert that into another area of your database. Another table, for example. There's a lot of stuff you can do. You can retrieve the data from it. And yeah, planning stuff.
So thanks for watching any questions, feel free to pop me, you know a message and I look forward to seeing you in the next video.