开发者

Add an item to SQL and get auto incrementing id back immediately

开发者 https://www.devze.com 2023-04-11 16:10 出处:网络
I\'m using the following code to add a entry to my SQL database. $RQ1_string = \"INSERT INTO automotive_RQ01_Information VALUES(NULL,\'\".$title.\"\',\'\".$description.\"\')\";

I'm using the following code to add a entry to my SQL database.

$RQ1_string = "INSERT INTO automotive_RQ01_Information VALUES(NULL,'".$title."','".$description."')";
$RQ1_result = mysql_query($RQ1_string);

In the next line I need to use the value of the auto-incrementing ID开发者_开发问答(The NULL entry).

How can I get the ID from RQ1_result?


You would use mysql_insert_id(). This can be assigned to a variable or outputted directly.

http://www.php.net/manual/en/function.mysql-insert-id.php

0

精彩评论

暂无评论...
验证码 换一张
取 消