Getting id of row just inserted into MySQL database
- by James P
I have my table columns set like this:
likes(id, like_message, timestamp)
id is the primary key that is auto incrementing. This is the SQL that I use to add a row:
$sql = "INSERT INTO `likes` (like_message, timestamp)
VALUES ('$likeMsg', $timeStamp)";
Everything works, but now I need to throw back the id attribute of the newly inserted row. For example, if I insert a row and the id of that row is 13, I need to echo out 13 so my AJAX request can pick that up and use it.
Any help would be appreciated, as well as related code samples. Thanks :)