How to get the auto-incremented index ?

A

Anonymous

Guest
Hi guys,

If someone posts a message in my forum, this code will be executed:

$query = "insert into forum values ('', '$subject, '$iconid', '', '')";
$result = mysql_db_query ("vibDB", $query);

$fIndex = mysql_result ($result, 0, "forumIndex");

$query2 = "insert into forumReplies values ('', '$message', '1', '', '1', 'fIndex')";
$result2 = mysql_db_query ("vibDB", $query2);


In the first query, the first parameter(before the subject) is an auto-incremented field, so this gets filled in automatically.
But I want to get this field back to put it into another table where I need it.
The auto-incremented field is named forumIndex, so I based on the result I want to get it by doing this:

- $fIndex = mysql_result ($result, 0, "forumIndex");


But it gives an error if I do this.
But how can I get the auto-incremented value from this post back ?
 
Code:
mysql_insert_id ( [resource link_identifier])
will return the ID generated in an AUTO_INCREMENT field of the previous insert query.

search the php-manual for more details on the function (I use it locally and not online, so can't give you a link rightnow)

Greetz Daan
 
dvdbinternet said:
Code:
mysql_insert_id ( [resource link_identifier])
search the php-manual for more details on the function (I use it locally and not online, so can't give you a link rightnow)

A quick and easy way to search the online manual is to go to http://www.php.net/function_name without the brackets

eg http://www.php.net/mysql_insert_id
 
Back
Top