Getting id of row just inserted into MySQL database
Posted
by James P
on Stack Overflow
See other posts from Stack Overflow
or by James P
Published on 2010-06-08T21:57:08Z
Indexed on
2010/06/08
22:02 UTC
Read the original article
Hit count: 133
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 :)
© Stack Overflow or respective owner