如何知道最近对MySQL进行的条目的id(自动增量)?

Dom*_*oSL 0 php mysql

我的用户填写一个将数据发送到数据库(MySQL)的表单,然后将用户重定向到一个php脚本,该脚本最近由用户呈现信息,但是渲染脚本需要用户输入的数据的id,i需要从表单中发布这些数据,有什么想法吗?

这是插入的php代码:

$sql = "INSERT INTO `freedomshare`.`post` (`id`, `title`, `content`, `datetime`, `author`, `private`, `password`, `comments`, `qrcode`, `counter`, `editable`, `active`) VALUES (NULL, '" . addslashes($_POST['title']) . "', '" . addslashes($_POST['input']) . "', NOW(), '" . addslashes($_POST['author']) . "', $private,'" . addslashes($_POST['password']) . "', $comments, $qrcode, '0', $editable, '1');";
mysql_query($sql);
Run Code Online (Sandbox Code Playgroud)

有没有办法知道执行这行后id获得的值?

Nic*_*can 6

是.

你可以使用php函数mysql_insert_id http://us3.php.net/manual/en/function.mysql-insert-id.php