Philip Kirkbride
Philip Kirkbride

Reputation: 22889

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

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?

Upvotes: 0

Views: 209

Answers (1)

James Williams
James Williams

Reputation: 4216

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

Upvotes: 1

Related Questions